Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
783 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...