Home > Blockchain >  How to use SuperTokens refreshSession?
How to use SuperTokens refreshSession?

Time:09-20

I have written following snippet of code in NodeJs to use cookies are set in postman before request to refresh session So I am confused, to how to use refreshSession in SuperTokens. I don't know the problem is from which side, it is because of SuperTokens or Postman or ExpressJs! I have checked the postman and it is sending the cookies correctly until calling the /refresh url.

Could you please guide me where is the problem and how I can solve it?

Thanks in advance.

CodePudding user response:

You have missed out on adding the supertokens middleware to your app. You should add it like the following:

let { middleware } = require("supertokens-node/framework/express");

// ...

let app = express();
app.use(middleware());


//... rest of your code

The middleware adds a few APIs to your app:

  • The refresh endpoint
  • The sign out endpoint

If you initialise other recipes, it will add endpoints specific to those recipes.

This way, you can remove your implementation of the refresh API, and the way you can query your app to refresh is to query http://localhost:1919/auth/session/refresh POST with an empty body. Assuming that Postman will send the refresh token in the request, it should yield a 200 response.

  • Related