https://supertokens.com/ logo
v

veritas

07/18/2022, 6:39 PM
Can I get some help with troubleshooting? I have a user who can't log in, but don't see any reason in the logs.
r

rp

07/18/2022, 6:40 PM
Hey! Yea sure. What is the user doing? And which browser are they using?
v

veritas

07/18/2022, 6:42 PM
Chrome. They're trying to sign up for the first time via GitHub but get the "Something went wrong" error.
r

rp

07/18/2022, 6:43 PM
Hmmm. Is that just happening to that user? And no one else?
v

veritas

07/18/2022, 6:43 PM
It's happening to two users.
But I can't see any error in the server logs.
r

rp

07/18/2022, 6:44 PM
I see. What is the reply from the api for /signinup API?
v

veritas

07/18/2022, 6:44 PM
They say this is in the logs: "variable (__supertokensOriginalFetch) undefined"
r

rp

07/18/2022, 6:44 PM
Hmmm.
Is that the only logs?
v

veritas

07/18/2022, 6:45 PM
Yeah.
What's your GitHub? Could I add you so you can try logging in?
r

rp

07/18/2022, 6:45 PM
Strange.
Yea sure. My GitHub is rishabhpoddar
Please add me
I’ll try logging in now
v

veritas

07/18/2022, 6:48 PM
I need to add you to our allow-list, will let you know once that's done
r

rp

07/18/2022, 6:49 PM
cool.
v

veritas

07/18/2022, 6:49 PM
I assume SuperTokens doesn't have any issues with Firefox? I've only tested on Chrome.
r

rp

07/18/2022, 6:50 PM
no issues with firefox
v

veritas

07/18/2022, 6:55 PM
r

rp

07/18/2022, 6:55 PM
thanks
seeing now
right.. so i can see the issue as well.
The signinup API is returning a 500 error
So probably some issue on your server customisation code?
Do you see any logs there for it?
v

veritas

07/18/2022, 6:58 PM
Nope, I don't see any errors showing up there.
r

rp

07/18/2022, 6:59 PM
hmm. Can I see the customisation that you have made for the signinup API? How are you handling erros in your app? Cause the API is returning 500 error code, which means that the API throws some error.
v

veritas

07/18/2022, 7:01 PM
I'm using the supertoken error handler:
Copy code
app.setErrorHandler(errorHandler());
r

rp

07/18/2022, 7:01 PM
ah right. Can you add a generic erorr handler to your app?
like:
Copy code
app.use((err, req, res, next) => {
  console.log(err)
  next(err);
})
and add that AFTER the supertokens error handler.
v

veritas

07/18/2022, 7:02 PM
r

rp

07/18/2022, 7:02 PM
What is the output?
customisation seems about right.. one of the functions being called is probably throwing an error.
or you could wrap the whole thing in a try / catch and see what the error is like this:
Copy code
apis: (originalImplementation) => {
              return {
                ...originalImplementation,
                signInUpPOST: async function (input) {
                  if (originalImplementation.signInUpPOST === undefined) {
                    throw Error("Should never come here");
                  }
                  try {
                    let response = await originalImplementation.signInUpPOST(
                      input
                    );

                    if (response.status === "OK") {
                      const user = new UserAccount(response.user.id);
                      const token = response.authCodeResponse.access_token;
                      await user.saveAccessToken(Providers.GitHub, token);
                    }

                    return response;
                  } catch (err) {
                    console.log(err)
                    throw err;
                  }
                },
              };
            },
          },
        }),
v

veritas

07/18/2022, 7:06 PM
Thanks, deploying now.
r

rp

07/18/2022, 7:06 PM
cool
v

veritas

07/18/2022, 7:11 PM
I think I found the issue. Is it correct that a session is created before the signInAndUp function is called?
r

rp

07/18/2022, 7:13 PM
You mean before
originalImplementation.signInUpPOST
is called? Or the override.functions.signInUp function?
v

veritas

07/18/2022, 7:13 PM
The override function one.
r

rp

07/18/2022, 7:13 PM
right. So the function there is called
signInUp
and not
signInAndUp
But, the session is created after that function returns
v

veritas

07/18/2022, 7:14 PM
Huh, weird. It seems like the session creation is happening first.
And that's failing because our session handler attempts to get the token.
r

rp

07/18/2022, 7:14 PM
So signInUpPOST calls: - signInUp - If signInUp returns success, then createNewSession is called from the session recipe.
Which session are you referring to? The github access_token? Or the supertokens session?
v

veritas

07/18/2022, 7:15 PM
Supertokens
r

rp

07/18/2022, 7:16 PM
right. So SuperTokens session is created after signInUp function is called
v

veritas

07/18/2022, 7:16 PM
But before signInUpPost?
This part was failing
r

rp

07/18/2022, 7:17 PM
yes, before signInUpPost returns
right. And it's failing with what error?
v

veritas

07/18/2022, 7:17 PM
It can't find the token in the DB
r

rp

07/18/2022, 7:18 PM
ah i see.
v

veritas

07/18/2022, 7:18 PM
Since we save the token in signInUpPost
r

rp

07/18/2022, 7:18 PM
so the token from the db is added after signInUpPost returns. But createNewSession is called before signInUpPost returns
v

veritas

07/18/2022, 7:18 PM
Exactly
Should I be saving the token in a different hook?
r

rp

07/18/2022, 7:22 PM
No. You will have to save post signInUpPost returns, but instead of adding the role in createNewSession, you can add the role after you have saved the access token in the db. You can do that by using response.session.updateAccessTokenPayload function
v

veritas

07/18/2022, 7:23 PM
Can you try logging in now? I think that fixed it.
r

rp

07/18/2022, 7:23 PM
let me try.
works!
Aweosme
v

veritas

07/18/2022, 7:25 PM
Thanks so much for your help!