supertokens / supertokens-node

Node SDK for SuperTokens core
https://supertokens.com
Other
278 stars 72 forks source link

Supertokens server is crashing when we call Session.getSession #786

Closed RoushanSingh-dot closed 5 months ago

RoushanSingh-dot commented 5 months ago

If the session is expired, supertokens is logging error failed to verify access token but the server is crashing after that call.

If we wrap this code inside try catch, then it is working absolutely fine.

So, the issue is error handler not handling this error.

RoushanSingh-dot commented 5 months ago

Steps to reproduce:

call this function and log the result:
let session = await Session.getSession(req, res); console.log(session);

Pass 'Cookie' with invalid data. Or any expired access token.

It is supposed to give error but if we don't wrap the above code inside try-catch, the server crashes.

porcellus commented 5 months ago

In express, you can't directly throw errors in the in the API handler code, but pass it to the next function (the third param passed to the handler function). If you do that this works as expected. On a related note, in most situations we recommend using the verifySession middleware instead of calling getSession directly. Related discord thread: https://discordapp.com/channels/603466164219281420/1199674501093412914