Nuxt Auth strategy doesn't fetch authentication token

871 Views Asked by At

I have the following authentication strategy:

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

Oddly enough, this strategy completes all the authentication by itself, without ever hitting my backend! Shouldn't responseType code go to endpoints.token to get the token?

My login function looks like this:

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

Interestingly enough, if I don't pass the params here, Google gives me an error that client_id is missing.

2

There are 2 best solutions below

1
On

This is a problem with @nuxtjs/auth, which is the version <= v4.9.1, and as the documentation warns that it may contain bugs and un-implemented functionalities.

Using v5, named @nuxtjs/auth-next would fix the issue.

Install as:

yarn add --exact @nuxtjs/auth-next

Then add to your nuxt.config.js as (from the documentation):

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

Documentation is wrong. Use client_id , redirect_uri , etc, snake case instead, this worked for me