Skip to content

fix(client): only fetch claims when the signed-in user changes - #655

Open
dax-side wants to merge 1 commit into
nuxt-modules:mainfrom
dax-side:fix-claims-same-user
Open

dax-side wants to merge 1 commit into
nuxt-modules:mainfrom
dax-side:fix-claims-same-user

Conversation

@dax-side

Copy link
Copy Markdown

Types of changes

  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

Resolves: #650

The client plugin called getClaims() on every auth state change. When the device clock is about an hour or more ahead, auth-js treats every new token as expired, so getClaims() refreshes the session, which emits TOKEN_REFRESHED, which calls getClaims() again: an endless refresh loop.

The onAuthStateChange handler now only fetches claims when the session belongs to a different user than the current one (session.user.id !== currentUser.value?.sub). The session state is still updated on every event, and page:start still refreshes the claims on navigation. This is the change suggested in the issue.

I added test/supabase-client-plugin.test.ts, which runs the plugin with mocked #imports and a mocked client: repeated TOKEN_REFRESHED events for the same user no longer call getClaims(), while a different user signing in and signing out still update the user.

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes (if not applicable, please state why)

@vercel

vercel Bot commented Nov 10, 2026

Copy link
Copy Markdown

@dax-side is attempting to deploy a commit to the NuxtLabs Team on Vercel.

A member of the Team first needs to authorize it.

@pkg-pr-new

pkg-pr-new Bot commented Nov 10, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/@nuxtjs/supabase@655

commit: 259a29f

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Infinite token refresh loop when the device clock is >= 1 h ahead

1 participant