access token expiring
# support-questions
h
Hi team, when I implement this code, I got error Failed to verify access token I am using "supertokens-node": "13.4.1" with Express and already setup this https://supertokens.com/docs/passwordless/custom-ui/init/backend#3-add-the-supertokens-apis--cors-setup This happen when I leave the browser and come back after a few hours but this will be gone if I clear the cookies on browser and login again. What should I do to avoid this?
Copy code
import Session from 'supertokens-node/recipe/session';
const session = await Session.getSession(req, res, { sessionRequired: false });
if (session !== undefined) {
   let userId = session.getUserId();
}

https://cdn.discordapp.com/attachments/644849840475602944/1098666007234625568/image.png

r
hey @hwihwi this is expected. It happens when the access token has expired. Our frontend SDK should do an auto refresh in this case. Can i see the API request being made? Specifically, the request headers.
h
Hi @rp here it is

https://cdn.discordapp.com/attachments/1098666007087808723/1098669107408277584/image.png

r
right. if this returns 401, it should do an auto refresh.
h
but after a few hours or even a day I come back to browser It throws Error: Failed to verify access token at /node_modules/supertokens-node/lib/build/recipe/session/accessToken.js:89:19 Anyway I can prevent or workaround with it?
r
no way to prevent that. It should trigger an auto refresh
can you set the access token's life time in the core to 1 min
and then login, and see if after one min it auto refreshes when an API returns 401?
h
Thanks @rp , now it works OK now with 401 then refresh and 200
r
right. So if you set it back to the default value, then try again after sometime.. it should work fine. If you get this error again, please let us know