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

Closed
luthfihizb opened this issue Sep 18, 2024 · 4 comments
Closed

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

luthfihizb opened this issue Sep 18, 2024 · 4 comments
Labels
bug A bug that needs to be resolved closed-by-bot Closed by automation needs-reproduction Action needed: A valid reproduction of the issue needs to be added 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,
    }

@luthfihizb
Copy link
Author

Maybe for your use case enabling period refresh will work

enabling period refresh only works if the tab is open.. meanwhile the issue still occurs if the token expires while the tab is closed

@zoey-kaiser zoey-kaiser added the needs-reproduction Action needed: A valid reproduction of the issue needs to be added label Oct 9, 2024
Copy link

github-actions bot commented Oct 9, 2024

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.

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:

Copy link

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

@github-actions github-actions bot added the closed-by-bot Closed by automation label Oct 24, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 24, 2024
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 closed-by-bot Closed by automation needs-reproduction Action needed: A valid reproduction of the issue needs to be added pending An issue waiting for triage
Projects
None yet
Development

No branches or pull requests

3 participants