-
Notifications
You must be signed in to change notification settings - Fork 183
Description
The user session fetch method appears to have a "catch all" that swallows all troubles silently, then pretends the session is ready.
nuxt-auth-utils/src/runtime/app/composables/session.ts
Lines 29 to 39 in f55debb
| const fetch = async () => { | |
| sessionState.value = await useRequestFetch()<UserSession>('/api/_auth/session', { | |
| headers: { | |
| accept: 'application/json', | |
| }, | |
| retry: false, | |
| }).catch(() => null) | |
| if (!authReadyState.value) { | |
| authReadyState.value = true | |
| } | |
| } |
That is troublesome in case of failure, since the application user code has no way of detecting it, and no way of reporting the trouble.
I have searched the file history and saw it was there since the creation of the file, so, I found no explanation for this in the source. I have also searched issues without finding any about this.
What is the rationale for this implementation?
Should it be changed?
Underlying trouble that caused me to see this: I have implemented a "refresh" of the user session data by calling this fetch periodically (through setTimeout). It is meant for detecting if it has been changed through actions on another tab of the browser. When a fetch failure occurs, it causes the user data to switch to null, causing the Web site to switch to "unauthenticated" mode, while actually, the authentication is still there: reloading entirely the page allows it to switch back to logged in.
More troublesome to me, I have no way to see the fetch has actually failed to diagnose and fix the trouble, or at least, handle some retry logic. (In the browser, in my case, the trouble seems the HTTP request being sometime cancelled, appearing in the browser network pane without any response. No idea what would cause that cancellation.)