Catching SuperTokens errors on the frontend
How can I catch errors in SuperTokens.init on the frontend. Assuming I get a 500 Internal Server Error because the supertokens core server cannot be reached. Btw I stopped the server intentionally to see how I might handle such errors. Currently my react app just goes blank and I see this in the browser console: XHR POST http://localhost:3000/session/refresh [HTTP/1.1 500 Internal Server Error 599ms]
Thanks for opening this issue @alfreddohnani . We will have a look at this ASAP
Which version of the supertokens-auth-react SDK are you using?
0.23.1
This error doesn't happen inside SuperTokens.init, the request is likely started by either an "auth" component (e.g.: EmailPasswordAuth) or calling doesSessionExist. In my quick experiment, it seems to work correctly. Here's what I tried:
- I logged in with a user
- I delete a cookie to make the SDK call refresh
- I respond with a 500 error to
/auth/session/refresh(the basepath shouldn't make a difference) Then, I get redirected to the auth screen (if I haverequireAuthset to true in the auth component) or I get the result that the session doesn't exist. This is what I'd expect. Can you tell us a bit more about your setup? Maybe a repo or some code I could check out? I'm happy to get on a call and check it out on screen share as well.
I'll prepare a repo and get back to you on this
Does the network tab on the frontend also call an API to check for email verification as well? And does that return 500 as well?
@rishabhpoddar here is the repro
The use case I'm trying to build here is a Single Sign-On app for a number of applications
Does the network tab on the frontend also call an API to check for email verification as well? And does that return 500 as well?
No please. I'm not yet tackling email verification.
Thanks @alfreddohnani we will check it out
I checked it out, but I'm still not 100% sure about replicating your issue. One of the flows I tried:
- Started core
- Went to
app-one(http://localhost:4001) - I got redirected to
app-auth(http://localhost:3001), where I signed up - Got redirected back to
app-one - Stopped core
- Refresh the page - nothing happened
- Deleted
sIRTFrontendcookie to trigger a session refresh - Refreshed the page - got redirected back to the auth page as expected
Did I miss something?
Interesting. When I stop the core(and at this point my session has expired) I don't get redirected. The session refresh endpoint is called and returns 500 and that's it.
I'm not sure how to replicate (and fix) this. Just to check:
- what browser are you using (incl. version)?
- are you in incognito mode? I'm happy to try and investigate this on a screen share as well. The #547 issue might be related, you could check out if the same fix works for you (when/after that gets fixed)
what browser are you using (incl. version)?: Firefox Developer Edition v104.0b3 are you in incognito mode?: No I'm happy to try and investigate this on a screen share as well: how might we proceed with this?
Oh, sorry for the late response. This got a bit lost in my notifications. So everything seems to be in order; incognito could've caused issues. About screen sharing: if you have discord, you could join our server, and we could set up a time there, or I could send you a calendly link.
Closing this issue due to inactivity. Please feel free to reopen if the error persists.