Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
995 views
in Technique[技术] by (71.8m points)

nuxt.js - Nuxt Auth module GitHub

I have setup the Nuxt auth module in the nuxt.config.js and created an application on GitHub. Logging works, however I'm trying a simple axios call and I'm not sure what I'm doing wrong:

<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>

The above gives a POST 404 error in the console

question from:https://stackoverflow.com/questions/65951653/nuxt-auth-module-github

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

loginWith() function is a promise. You have forgot the await or the .then() to handle the response:

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

or

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

In addition, you have to catch the errors from loginWith promise.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...