https://supertokens.com/ logo
r

rp

05/01/2022, 8:09 AM
See NextJS section -> session verification -> ssr method. Even if you are not using NextJS, you can do something similar
r

rp

05/01/2022, 12:46 PM
Yes
g

gitcommitshow

05/01/2022, 12:46 PM
Ok. So, you are suggesting to use
Session.getSession
here?
r

rp

05/01/2022, 12:47 PM
Yes
g

gitcommitshow

05/01/2022, 12:50 PM
I wanted to have similar workflow as `verifySession`(setting req.session object by middleware). So in that case, here's what I'll do. 1. I'll create my own middleware
authenticate()
2. In this middleware, I will use
Session.getSession
to verify the session and then I'd add the session info in req.session object. Then at the route handler side, I can simply
req.session
to see if the session is valid or expiered.\
r

rp

05/01/2022, 12:53 PM
Yea. And then I case the getSession throws a try refresh token exception, you can return the html page you wanted to
g

gitcommitshow

05/01/2022, 12:53 PM
I was just writing that. If I find the error while verifying session to be
Session.Error.TRY_REFRESH_TOKEN
, I will start refresh token process (I still needs to learn about that)
User does not need to login for this case, right?
r

rp

05/01/2022, 12:53 PM
Yea.. well.. u should only use this for server side rendered routes
If u r doing this for an API call, that’s incorrect
For an api call, just use verifySession and all will work fine
If this doesn’t make sense, I suggest you see the how supertoeks works section first
g

gitcommitshow

05/01/2022, 12:56 PM
I'm handling both API and html from one express app. Vanilla js. Ejs for templating.
r

rp

05/01/2022, 1:07 PM
Ok. So for APIs, you should use verifySession and for server side rendered routes, you can use your custom middleware
g

gitcommitshow

05/01/2022, 5:30 PM
I am using same path for APIs and server side rendered routes. If the requested content-type is json, I return json otherwise the server side rendered html.
r

rp

05/02/2022, 4:48 AM
Okay
3 Views