Nuxt Auth module GitHub



我已经在nuext .config.js中设置了next auth模块,并在GitHub上创建了一个应用程序。日志工作,但我正在尝试一个简单的axios调用,我不确定我做错了什么:

<template>
<div>
<button v-on:click="signIn">click here</button>
</div>
</template>
<script>
export default {
methods: {
signIn () {
this.$auth.loginWith('github');
this.$axios.get('https://api.github.com/users/mapbox')
.then((response) => {
console.log(response.type);
console.log(response.id);
console.log(response.name);
console.log(response.blog);
console.log(response.bio);
});
}
}
}
</script>

上面在控制台

中给出一个POST 404错误。

loginWith()函数是一个承诺。您忘记使用await.then()来处理响应:

async signIn () {
await this.$auth.loginWith('github');
this.$axios.get('https://api.github.com/users/mapbox').then(...)
}

signIn () {
this.$auth.loginWith('github').then((data) => {
this.$axios.get('https://api.github.com/users/mapbox').then(...)
}

此外,您必须捕获loginWith承诺中的错误。

最新更新