sidebase / nuxt-auth

Authentication built for Nuxt 3! Easily add authentication via OAuth providers, credentials or Email Magic URLs!
https://auth.sidebase.io
MIT License
1.25k stars 162 forks source link

"refresh" strategy redirect to the login page on reload/direct link (already connected) #859

Open Suniron opened 1 month ago

Suniron commented 1 month ago

Environment


Reproduction

Put this config in the nuxt config file:

{
  baseURL: determineBaseUrl(),
  globalAppMiddleware: true,
  isEnabled: true,
  provider: {
    endpoints: {
      getSession: { method: 'get', path: `session` },
      refresh: { method: 'post', path: `refresh-token` },
      signIn: { method: 'post', path: `credentials` },
      signOut: { method: 'delete', path: `logout` },
      // @ts-expect-error disable sign up, like in the example from the docs: https://auth.sidebase.io/guide/local/quick-start#api-endpoints
      signUp: false,
    },
    pages: {
      login: '/login',
    },
    refreshToken: {
      cookieName: 'auth.refreshToken',
      maxAgeInSeconds: 2592000, // 30 days // TODO: fix this
      signInResponseRefreshTokenPointer: '/refreshToken',
    },
    session: {
      dataType: {
        companyHasAcceptedTermsOfUse: 'boolean',
        companyId: 'number',
        companyName: 'string',
        email: 'string',
        firstName: 'string',
        fullyConnected: 'boolean',
        id: 'string',
        isTwoFactorInitialized: 'boolean',
        lastName: 'string',
        roles: '(\'admin\' | \'member\')[]',
        username: 'string',
      },
    },
    token: {
      cookieName: 'auth.token',
      headerName: 'Authorization',
      maxAgeInSeconds: 900, // 15 minutes // TODO: fix this
      signInResponseTokenPointer: '/accessToken',
      type: 'Bearer',
    },
    type: 'refresh',
  },
  sessionRefresh: {
    // enableOnWindowFocus: true, // Avoid conflicts when switching tabs
    enablePeriodically: 5 * 60 * 1000, // every 5 minutes
  },
}

Describe the bug

When the type: 'refresh' is set, if i'm already connected and I try to reload my current page (or load a new in another tab), I'll automatically redirected to te /login page.

If I just replace the type: 'refresh' by type: 'local', I can access to a page directly without redirection to the login page...

Additional context

No response

Logs

No response