supertokens-auth-react icon indicating copy to clipboard operation
supertokens-auth-react copied to clipboard

Catching SuperTokens errors on the frontend

Open alfreddohnani opened this issue 3 years ago • 14 comments

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]

alfreddohnani avatar Jul 29 '22 10:07 alfreddohnani

Thanks for opening this issue @alfreddohnani . We will have a look at this ASAP

rishabhpoddar avatar Jul 29 '22 10:07 rishabhpoddar

Which version of the supertokens-auth-react SDK are you using?

rishabhpoddar avatar Jul 29 '22 11:07 rishabhpoddar

0.23.1

alfreddohnani avatar Jul 29 '22 11:07 alfreddohnani

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:

  1. I logged in with a user
  2. I delete a cookie to make the SDK call refresh
  3. 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 have requireAuth set 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.

porcellus avatar Aug 01 '22 15:08 porcellus

I'll prepare a repo and get back to you on this

alfreddohnani avatar Aug 01 '22 15:08 alfreddohnani

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 avatar Aug 03 '22 10:08 rishabhpoddar

@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

alfreddohnani avatar Aug 03 '22 18:08 alfreddohnani

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.

alfreddohnani avatar Aug 03 '22 18:08 alfreddohnani

Thanks @alfreddohnani we will check it out

rishabhpoddar avatar Aug 04 '22 08:08 rishabhpoddar

I checked it out, but I'm still not 100% sure about replicating your issue. One of the flows I tried:

  1. Started core
  2. Went to app-one (http://localhost:4001)
  3. I got redirected to app-auth (http://localhost:3001), where I signed up
  4. Got redirected back to app-one
  5. Stopped core
  6. Refresh the page - nothing happened
  7. Deleted sIRTFrontend cookie to trigger a session refresh
  8. Refreshed the page - got redirected back to the auth page as expected

Did I miss something?

porcellus avatar Aug 04 '22 10:08 porcellus

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.

alfreddohnani avatar Aug 04 '22 11:08 alfreddohnani

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)

porcellus avatar Aug 04 '22 13:08 porcellus

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?

alfreddohnani avatar Aug 08 '22 18:08 alfreddohnani

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.

porcellus avatar Aug 11 '22 09:08 porcellus

Closing this issue due to inactivity. Please feel free to reopen if the error persists.

rishabhpoddar avatar Aug 18 '22 18:08 rishabhpoddar