From 189e35acf88eb66d81619297aafd83b020bec01d Mon Sep 17 00:00:00 2001 From: Joakim Olsson Date: Tue, 5 May 2026 17:36:59 +0000 Subject: [PATCH] fix(apollo): logout on stale Auth0 token errors (#2887) --- app/plugins/apollo.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/plugins/apollo.ts b/app/plugins/apollo.ts index bc7ea9e..cc4e4d4 100644 --- a/app/plugins/apollo.ts +++ b/app/plugins/apollo.ts @@ -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 }) }