You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently looking at error handling for a Next application using NextAuth. More specifically, I want to display a custom error page / component if something goes wrong while fetching the user session.
What I understand so far is that if anything goes wrong while fetching the session via useSession, it will not throw but act as if the user was not logged-in. This comes from this part of the code where _fetchData resolves with null in case of any error. There is the same pattern on the server side if the session callback is throwing, cookies are unset and we simply return {}.
In my case, I'd prefer this to throw so that I can either catch this error (when using getSession) or handle it an error boundary (when using useSession). This is because I have so protected pages that automatically redirect to the signin page if the user is null. If there is really an issue with the session retrieval, I'd rather be explicit to the user instead of asking them to login again for nothing.
Is this already possible or could we add an option for enabling this behavior?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm currently looking at error handling for a Next application using NextAuth. More specifically, I want to display a custom error page / component if something goes wrong while fetching the user session.
What I understand so far is that if anything goes wrong while fetching the session via
useSession
, it will not throw but act as if the user was not logged-in. This comes from this part of the code where_fetchData
resolves withnull
in case of any error. There is the same pattern on the server side if thesession
callback is throwing, cookies are unset and we simply return{}
.In my case, I'd prefer this to throw so that I can either catch this error (when using
getSession
) or handle it an error boundary (when usinguseSession
). This is because I have so protected pages that automatically redirect to the signin page if theuser
is null. If there is really an issue with the session retrieval, I'd rather be explicit to the user instead of asking them to login again for nothing.Is this already possible or could we add an option for enabling this behavior?
Beta Was this translation helpful? Give feedback.
All reactions