小编4er*_*ern的帖子

Nuxt Auth-未设置用户数据

我尝试通过nuxt-auth模块进行登录。作为响应,我得到了令牌,然后传递了用户数据。但是,this.$Auth.loggedInis falsethis.$Auth.useris undefined。我已经战斗了3天,无法继续前进。希望有人能帮助我。

登录

await this.$auth.login({
    data: {
        email: this.email,
        password: this.password
    }
}).then(() => {
    this.$router.push('/dashboard')
}).catch(err => {
    this.snackbar.show = true;
})
Run Code Online (Sandbox Code Playgroud)

nuxt.config.js

auth: {
    strategies: {
        local: {
            endpoints: {
                login: {
                    url: '/auth/login',
                    method: 'post',
                    propertyName: 'access_token'
                },
                logout: {
                    url: '/auth/logout',
                    method: 'post'
                },
                user: {
                    url: '/auth/me',
                    method: 'post'
                },
                tokenRequired: true
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

响应登录

{
"access_token": "xxxxxxxxxxxxx.eyJpc3MiOiJodHRwczpcL1wvYXBpLmFwcHJlexxxxxxxcxXRoXC9sb2dpbiIsImlhdCI6MTUzODI5NTczMywiZXhwIjoxNTM4Mjk5MzMzLCJuYmYiOjE1MzgyOTU3MzMsImp0aSI6ImdtWWVyZTViQjk1cU5BRG8iLCJzdWIiOjIsInBydiI6IjYwODM2NzQ0MzQ4ZDQzMTk4NzE4N2ZjMWM2YzIzMjYxMDcyMWE5ZjAifQ.JhOiwIg7StzZR71aqYyI9rJpPXVclmddzPSIwqCIUN4",
"token_type": "bearer",
"expires_in": 3600
}
Run Code Online (Sandbox Code Playgroud)

回应使用者

{
    "id": …
Run Code Online (Sandbox Code Playgroud)

authentication axios vuex nuxt.js

1
推荐指数
2
解决办法
1990
查看次数

标签 统计

authentication ×1

axios ×1

nuxt.js ×1

vuex ×1