The enableOnWindowFocus feature should not be triggered on pages that are accessible to unauthenticated users. Currently, when a user switches back to a tab containing an unauthenticated page (such as the login page of us), the refresh mechanism is still executed, which is unnecessary and potentially problematic.
In the current implementation in src/runtime/utils/refreshHandler.ts, there's an inconsistency in how enablePeriodically and enableOnWindowFocus are handled.
For enablePeriodically, there's a check for the authenticated state:
Environment
Reproduction
Describe the bug
The enableOnWindowFocus feature should not be triggered on pages that are accessible to unauthenticated users. Currently, when a user switches back to a tab containing an unauthenticated page (such as the login page of us), the refresh mechanism is still executed, which is unnecessary and potentially problematic.
In the current implementation in
src/runtime/utils/refreshHandler.ts
, there's an inconsistency in howenablePeriodically
andenableOnWindowFocus
are handled. ForenablePeriodically
, there's a check for the authenticated state:https://github.com/sidebase/nuxt-auth/blob/9295d1fe4f27d42c879862a48202f5b215fc0048/src/runtime/utils/refreshHandler.ts#L35-L42
However, for
enableOnWindowFocus
, no such check exists: https://github.com/sidebase/nuxt-auth/blob/9295d1fe4f27d42c879862a48202f5b215fc0048/src/runtime/utils/refreshHandler.ts#L72-L79 To resolve this issue and ensure consistency, we should add an authentication check forenableOnWindowFocus
as well. A proposed solution is to add a condition like:This change would prevent unnecessary refresh attempts on unauthenticated pages and align the behavior with
enablePeriodically
. Thanks.Additional context
No response
Logs