Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't Refresh Token When Expired and Tab is Closed #914

Open
luthfihizb opened this issue Sep 18, 2024 · 1 comment
Open

Doesn't Refresh Token When Expired and Tab is Closed #914

luthfihizb opened this issue Sep 18, 2024 · 1 comment
Labels
bug A bug that needs to be resolved pending An issue waiting for triage

Comments

@luthfihizb
Copy link

Environment

  • Operating System: Windows_NT
  • Node Version: v20.17.0
  • Nuxt Version: 3.12.4
  • CLI Version: 3.12.0
  • Nitro Version: 2.9.7
  • Package Manager: [email protected]
  • Builder: -
  • User Config: -
  • Runtime Modules: @sidebase/[email protected]
  • Build Modules: -

Reproduction

Here is my auth config

auth: {
    isEnabled: true,
    disableServerSideAuth: false,
    globalAppMiddleware: true,
    baseURL: `${process.env.API_HOST}/v1/auth/`,
    provider: {
      type: "local",
      endpoints: {
        signIn: { path: "login", method: "post" },
        getSession: { path: "session", method: "get" },
      },
      token: {
        signInResponseTokenPointer: "/data/token",
        cookieName: "_auth_t",
        maxAgeInSeconds: 10,
        cookieDomain: "localhost",
      },
      refresh: {
        isEnabled: true,
        refreshOnlyToken: true,
        endpoint: {
          path: "refresh",
          method: "post",
        },
        token: {
          signInResponseRefreshTokenPointer: "/data/refreshToken",
          cookieName: "_auth_r",
          maxAgeInSeconds: 3600 * 24 * 7,
          cookieDomain: "localhost",
        },
      },
      session: {
        dataType: {
          id: "number",
          username: "string",
          name: "string",
        },
      },
    },
  },

Describe the bug

Currently, I'm testing what happens when the access token expires by simulating a very short expiration time (10 seconds). If the access token expires while the tab is still open (but I switch to another tab), when I refocus the tab, the access token refreshes fine..

image

But if the tab is closed when the access token is expired, the refresh mechanism is somehow ignored, and the user is redirected to the login page even though the refresh token still exists in the cookies. Reloading the tab also does not trigger the refresh.

image

Is this behavior expected? What I expect is that refocusing existing tab, reloading the tab, or opening a new tab should have the same behavior, right?

Additional context

No response

Logs

No response

@luthfihizb luthfihizb added bug A bug that needs to be resolved pending An issue waiting for triage labels Sep 18, 2024
@andychukse
Copy link
Contributor

enableOnWindowFocus is true by default. Maybe for your use case enabling period refresh will work.

sessionRefresh: {
        enablePeriodically: 1000 * 10,
        enableOnWindowFocus: true,
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug that needs to be resolved pending An issue waiting for triage
Projects
None yet
Development

No branches or pull requests

2 participants