Auth-module: Authentication does not occur after callback from auth0 provider on statically generated nuxt site

Created on 20 Nov 2019  路  9Comments  路  Source: nuxt-community/auth-module

Version

v4.8.4

Reproduction link

https://github.com/nuxt-community/auth-module

Steps to reproduce

Setup nuxt with typescript.
Install auth module @nuxtjs/auth @nuxtjs/axios @types/nuxtjs__auth
Configure auth0 provider https://auth.nuxtjs.org/providers/auth0.html
Setup login and callback routes.
Generate static.
Run http-server ./ in the dist folder.
Open browser and login (localhost:3000)

What is expected ?

The user should be authenticated after auth0 redirects to the callback.

What is actually happening?

Auth0 redirects to /callback, but the user is not authenticated.

Additional comments?

Running the application normally (without static) works.
Setting mode to universal or spa has no effect.

This bug report is available on Nuxt community (#c447)
bug

Most helpful comment

@DjustinK, did you manage to find a way around this? I'm seeing the exact same issue :cry:

Update: Managed to fix this by downgrading to 4.7.0

All 9 comments

login.vue

<script lang="ts">
import { Component, Vue } from 'nuxt-property-decorator';

@Component({
  name: 'Login'
})
export default class Login extends Vue {
  public mounted(){
    this.$auth.loginWith('auth0')
  }
}
</script>

callback.vue

<script lang="ts">
import { Component, Vue } from 'nuxt-property-decorator';

@Component({
  name: 'Callback'
})
export default class Login extends Vue {}
</script>

nuxt.config.ts

  modules: [
    '@nuxtjs/auth',
    '@nuxtjs/axios',
  ],
  router: {
    middleware: 'auth'
  },
  auth: {
    strategies: {
      auth0: {
        domain: ', // Fill
        client_id: '', //Fill
      }
    },
    redirect: {
      login: '/login',
      logout: '/logout',
      callback: '/callback',
      home: '/'
    }
  }

@DjustinK, did you manage to find a way around this? I'm seeing the exact same issue :cry:

Update: Managed to fix this by downgrading to 4.7.0

Having same issue :(

I figured it out, auth0 always appends a forward slash at the end of the callback url.
So basically you need to set '/callback/' in your application and in the auth0 callback url settings.
I also set my application in spa mode.
Tested with the latest nuxt/vue versions.

I figured it out, auth0 always appends a forward slash at the end of the callback url.
So basically you need to set '/callback/' in your application and in the auth0 callback url settings.
I also set my application in spa mode.
Tested with the latest nuxt/vue versions.

@DjustinK did it also work in "universal" mode? In my case adding "/" at the end of the callback url only fixes it in "spa" mode. Is there a reason for it?

I figured it out, auth0 always appends a forward slash at the end of the callback url.
So basically you need to set '/callback/' in your application and in the auth0 callback url settings.
I also set my application in spa mode.
Tested with the latest nuxt/vue versions.

@DjustinK did it also work in "universal" mode? In my case adding "/" at the end of the callback url only fixes it in "spa" mode. Is there a reason for it?

Have you fixed this already? I get redirected to my callback page but still see that I'm not authenticated. I have to manually refresh the page for it to show me that I'm authenticated. Using SSR univarsal mode.

@amirakbulut no unfortunately it is still not working

I suggest adding the onRedirect and onError listeners for better debugging.

I got it to work by wrapping the login buttons in client only inspired by this comment

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Amoki picture Amoki  路  3Comments

sebmor picture sebmor  路  3Comments

DiegoGallegos4 picture DiegoGallegos4  路  3Comments

pi0 picture pi0  路  3Comments

eatyrghost picture eatyrghost  路  3Comments