Skip to content

Refresh maxAgeInSeconds is too small (<25 days) #889

Closed
@cip8

Description

@cip8

Environment

  • Operating System: Linux
  • Node Version: v20.11.1
  • Nuxt Version: 3.13.0
  • CLI Version: 3.13.0
  • Nitro Version: 2.9.7
  • Package Manager: npm@10.2.4
  • Builder: -
  • User Config: runtimeConfig, build, app, modules, plugins, css, auth, devtools, devServer, compatibilityDate
  • Runtime Modules: @sidebase/nuxt-auth@0.9.1, @nuxtjs/tailwindcss@6.12.1
  • Build Modules: -

Reproduction

Set a number bigger than 24.85 days for the refresh token's maxAgeInSeconds.

My full config:

  auth: {
    isEnabled: true,
    globalAppMiddleware: {
      isEnabled: true,
      allow404WithoutAuth: true,
      addDefaultCallbackUrl: true,
    },
    baseURL: 'http://localhost:4100/v1/',
    provider: {
      type: 'local',
      endpoints: {
        signIn: { path: 'auth/login', method: 'post' },
        signOut: { path: 'auth/logout', method: 'post' },
        signUp: { path: 'auth/user', method: 'post' },
        getSession: { path: 'user/myself', method: 'get' },
      },
      pages: {
        login: '/',
      },
      token: {
        cookieName: 'at',
        type: 'Bearer',
        signInResponseTokenPointer: '/access_token',
        maxAgeInSeconds: 1800, // 30 min
        sameSiteAttribute: 'strict',
        secureCookieAttribute: true,
        cookieDomain: 'localhost',
        httpOnlyCookieAttribute: false,
      },
      refresh: {
        isEnabled: true,
        endpoint: { path: 'auth/refresh', method: 'post' },
        refreshOnlyToken: false,
        token: {
          cookieName: 'rt',
          signInResponseRefreshTokenPointer: '/refresh_token',
          refreshRequestTokenPointer: '/refresh_token',
          maxAgeInSeconds: 15552000, // 180 days
          sameSiteAttribute: 'lax',
          secureCookieAttribute: false,
          cookieDomain: 'localhost',
          httpOnlyCookieAttribute: false,
        }
      }
    },
    sessionRefresh: {
      enableOnWindowFocus: false,
      enablePeriodically: false,
    }
  },

Describe the bug

In JavaScript, the maximum delay you can set for setInterval() (or setTimeout()) is constrained by the maximum value for a signed 32-bit integer, which is 2,147,483,647 milliseconds.

This translates to approximately 24.85 days.

I'd like to use 180 days here, so if I assign 15552000 to maxAgeInSeconds this will be translated to 15,552,000,000 by the DefaultRefreshHandler at const intervalTime = provider.refresh.token.maxAgeInSeconds * 1e3;

The number is too big for the ensuing setInterval, which then triggers refreshes in an infinite refresh loop, in my case.

Additional context

Need different logic for the DefaultRefreshHandler setIntervals to work with bigger numbers too.

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementAn improvement that needs to be addedprovider-localAn issue with the local provider

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions