fix(apollo): logout on stale Auth0 token errors
dancefinder-app / build (pull_request) Successful in 2m57s
dancefinder-app / deploy-prod (pull_request) Has been skipped

When getAccessTokenSilently fails with login_required, invalid_grant,
missing_refresh_token, consent_required or interaction_required, log
the user out (without redirect) so the UI reflects reality instead of
appearing logged in while every authenticated query silently fails.
This commit is contained in:
2026-05-05 19:29:37 +02:00
parent 5e5071df2e
commit 00d6c08db2
+13 -1
View File
@@ -18,10 +18,22 @@ const cache = new InMemoryCache({
},
})
const STALE_AUTH_ERRORS = new Set([
'login_required',
'consent_required',
'interaction_required',
'invalid_grant',
'missing_refresh_token',
])
const getToken = async (options: GetTokenSilentlyOptions) => {
const nuxtApp = useNuxtApp()
const auth0: Auth0VueClient = nuxtApp.$auth0 as Auth0VueClient
return await auth0.getAccessTokenSilently(options).catch(() => {
return await auth0.getAccessTokenSilently(options).catch((err) => {
const code = err && typeof err === 'object' && 'error' in err ? (err as { error?: string }).error : undefined
if (code && STALE_AUTH_ERRORS.has(code)) {
auth0.logout({ openUrl: false }).catch(() => {})
}
return undefined
})
}