【发布时间】:2021-12-20 05:16:06
【问题描述】:
我在我的 nuxt 应用程序中为 nuxt-auth-next 使用以下配置
nuxt.config.js
auth: {
strategies:{
google: {
clientId: "my_client_id.apps.googleusercontent.com",
redirectUri: `http://localhost:3000/apps`,
codeChallengeMethod: '',
scope: ['profile', 'email'],
responseType: 'token id_token'
}
},
redirect: {
login: '/login',
logout: false,
home: '/apps',
callback: false
}
},
router: {
middleware: ['auth']
}
这是我的login.vue 文件
<template>
<div>
<div>
<template>
<b-button @click="loginClicked()">Login with Google</b-button>
</template>
</div>
</div>
</template>
<script>
export default {
methods: {
async loginClicked() {
try {
await this.$auth.loginWith('google');
} catch (err) {
console.log("login error: " + err);
}
}
}
}
</script>
当我从我的登录页面按Login with Google按钮时,它会进入Google身份验证页面,成功通过身份验证,进入localhost:3000/apps页面(我的重定向网址)然后立即返回到 localhost:3000/login - this.$auth.loggedIn 是假的。
我已经访问过https://github.com/nuxt-community/auth-module/issues/1127,但这并没有帮助。我错过了什么吗?
"@nuxtjs/auth-next": "5.0.0-1624817847.21691f1",
"nuxt": "^2.15.8"
【问题讨论】:
-
您好,您在 Vue devtools 中看到模块的登录状态是什么?
-
如果我在 devtools 中手动将loggedIn 编辑为“true”值,应用程序页面“apps”加载正常
-
如果我将 lib 从 nuxt/auth-next 更改为 nuxt/auth,授权工作正常
-
这完全取决于您是否需要最新的 v5 功能,或者 v4 是否足够好。
-
看来 v4 功能对我来说还可以