【问题标题】:Why user is not authenticated after google authorization in nuxt-auth-next?为什么在 nuxt-auth-next 中进行 google 授权后用户未通过身份验证?
【发布时间】: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"

按“使用 Google 登录”后的 Vue 开发工具

【问题讨论】:

  • 您好,您在 Vue devtools 中看到模块的登录状态是什么?
  • 如果我在 devtools 中手动将loggedIn 编辑为“true”值,应用程序页面“apps”加载正常
  • 如果我将 lib 从 nuxt/auth-next 更改为 nuxt/auth,授权工作正常
  • 这完全取决于您是否需要最新的 v5 功能,或者 v4 是否足够好。
  • 看来 v4 功能对我来说还可以

标签: vue.js nuxt.js nuxt-auth


【解决方案1】:

this page 所述,auth-next aka v5 仍处于测试阶段,您可能会遇到一些错误,即使它在功能方面更丰富。

如果您对 Nuxt 模块随 v4 提供的功能满意,那么坚持使用它可能是一个更稳定的解决方案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-28
    • 1970-01-01
    • 2023-03-26
    相关资源
    最近更新 更多