feat: enhance authentication error handling and schema fetching
Handle authentication errors related to consent and login in the Apollo client by redirecting users to the Auth0 login page as necessary. Update the schema-fetching logic to support dynamic references from the URL, removing mock data and improving overall data integrity in the application. Ensure proper loading states during the fetching process.
This commit is contained in:
@@ -51,8 +51,24 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[Apollo] Failed to get Auth0 token:', error)
|
||||
} catch (error: any) {
|
||||
// Handle consent required error
|
||||
if (error?.error === 'consent_required') {
|
||||
console.warn('[Apollo] Consent required, redirecting to login...')
|
||||
const auth0Instance = (nuxtApp.vueApp.config.globalProperties as any).$auth0
|
||||
// Trigger login with consent
|
||||
await auth0Instance.loginWithRedirect({
|
||||
authorizationParams: {
|
||||
prompt: 'consent',
|
||||
},
|
||||
})
|
||||
} else if (error?.error === 'login_required') {
|
||||
console.warn('[Apollo] Login required, redirecting...')
|
||||
const auth0Instance = (nuxtApp.vueApp.config.globalProperties as any).$auth0
|
||||
await auth0Instance.loginWithRedirect()
|
||||
} else {
|
||||
console.error('[Apollo] Failed to get Auth0 token:', error)
|
||||
}
|
||||
}
|
||||
|
||||
return { headers }
|
||||
|
||||
Reference in New Issue
Block a user