【问题标题】:Nuxt Auth strategy doesn't fetch authentication tokenNuxt Auth 策略不获取身份验证令牌
【发布时间】:2021-08-02 02:57:27
【问题描述】:

我有以下认证策略:

auth: {
    strategies: {
      local: {
        ...,
      },
      google: {
        clientId:
          "<MY CLIENT ID>",
        responseType: "code",
        endpoints: {
          token: "http://localhost:8000/social-login/google/",
          userInfo: "http://localhost:8000/auth/user/",
        },
      },
    },
    redirect: {
      ...
    },
  },

奇怪的是,这个策略自己完成了所有的身份验证,而不需要访问我的后端! responseTypecode不应该去endpoints.token获取token吗?

我的登录功能如下:

    loginWithGoogle() {
      this.$auth.loginWith("google", {
        params: {
          client_id:
            "<MY CLIENT ID>",
        },
      });
    },

有趣的是,如果我没有在这里传递参数,Google 会给我一个错误 client_id 丢失。

【问题讨论】:

    标签: nuxt.js nuxt-auth


    【解决方案1】:

    这是@nuxtjs/auth 的问题,它是v4.9.1 的版本,并且作为文档warns,它可能包含错误和未实现的功能。

    使用v5,命名为@nuxtjs/auth-next 可以解决此问题。

    安装为:

    yarn add --exact @nuxtjs/auth-next
    

    然后将nuxt.config.js 添加为(来自documentation):

    {
      modules: [
        '@nuxtjs/auth-next'
      ],
      auth: {
        // Options
      }
    }
    

    【讨论】:

    • 另外,尽量坚持使用特定版本以避免太多问题/重大更改。
    猜你喜欢
    • 2021-09-06
    • 2015-06-21
    • 2020-07-03
    • 2019-03-05
    • 1970-01-01
    • 2021-09-23
    • 2021-09-02
    • 1970-01-01
    • 2021-12-29
    相关资源
    最近更新 更多