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.31k stars 164 forks source link

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

Closed Suniron closed 3 weeks ago

Suniron commented 3 months 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

github-actions[bot] commented 1 month ago

Hello 👋

Please provide a reproduction for this issue 🙏

How can I create a reproduction? Please use one of the following links to reproduce your issue. - https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz - https://codesandbox.io/s/github/nuxt/starter/v3-codesandbox Please ensure that the reproduction is as **minimal** as possible. This will allow us to isolate the issue as best as possible. Here are some more amazing posts about the importance of reproductions: - [The Importance of Reproductions](https://antfu.me/posts/why-reproductions-are-required) - [How to Generate a Minimal, Complete, and Verifiable Example](https://stackoverflow.com/help/minimal-reproducible-example)
github-actions[bot] commented 3 weeks ago

This issue was closed because it was open for 14 days without a reproduction.