首页 > 解决方案 > Nuxt Auth 策略不获取身份验证令牌

问题描述

我有以下身份验证策略:

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: {
      ...
    },
  },

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

我的登录功能如下所示:

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

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

标签: nuxt.jsnuxt-auth

解决方案


这是@nuxtjs/auth版本 <=的问题v4.9.1,并且正如文档警告的那样,它可能包含错误和未实现的功能。

使用v5, named@nuxtjs/auth-next可以解决这个问题。

安装为:

yarn add --exact @nuxtjs/auth-next

然后添加到您的nuxt.config.jsas(来自文档):

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

推荐阅读