目前,我正在使用Nuxt Auth模块进行身份验证功能。在前端,我运行的是Nuxt,在后端,我运行的是FastApi。
在nuxt.config.js中,我设置了auth设置:
//Nuxt Auth module configuration https://auth.nuxtjs.org/schemes/local
auth: {
rewriteRedirects: false,
cookie: {
options: {
maxAge: 60 * 60 * 60 // 60 hours
}
},
localStorage: {
prefix: 'auth.'
},
strategies: {
local: {
token: {
prefix: 'access_token.',
property: 'access_token',
type: 'Bearer',
maxAge: 60 * 60 * 60
},
user: {
property: 'user',
autoFetch: true
},
endpoints: {
login: { url: '/api/v1/login/access-token', method: 'post' },
logout: false,
user: { url: '/api/v1/users/me', method: 'get' }
},
redirect: {
login: '/login',
logout: '/',
// callback: '/login',
home: '/dashboard'
}
}
}
}在我的Login.vue中,我有一个带有登录方法的表单:从'~/components/material/AppCard‘导入materialCard
export default {
components: {
materialCard
},
middleware: 'authenticated',
auth: 'guest',
data () {
return {
username: 'admin',
password: 'admin'
}
},
methods: {
async authenticate () {
const form = new FormData()
form.append('username', this.username)
form.append('password', this.password)
await this.$auth.loginWith('local', { data: form })
.then((res) => {
console.log(res)
}).catch((err) => {
console.log(err.res)
})
}
}
}当我尝试登录时,异步函数' login‘将被调用。返回与用户名和密码相对应的用户。我唯一的问题是,当我查看vuex状态时,auth.loggedIn保持为false,而auth.user保持未定义。
我以为Nuxt会自动更新状态,还是我遗漏了什么?
发布于 2022-11-28 05:10:38
我对oauth2也有同样的问题,请确保您的redirectUri已启用。当我设置redirectUri: '/'时,它不会调用redirectUri: '/'(),因为'/'是auth: false。更多我的发现:https://github.com/nuxt-community/auth-module/discussions/1592#discussioncomment-4250173
https://stackoverflow.com/questions/70107986
复制相似问题