See NextJS section -> session verification -> ssr ...
# support-questions
r
See NextJS section -> session verification -> ssr method. Even if you are not using NextJS, you can do something similar
r
Yes
g
Ok. So, you are suggesting to use
Session.getSession
here?
r
Yes
g
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
Yea. And then I case the getSession throws a try refresh token exception, you can return the html page you wanted to
g
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
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
I'm handling both API and html from one express app. Vanilla js. Ejs for templating.
r
Ok. So for APIs, you should use verifySession and for server side rendered routes, you can use your custom middleware
g
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
Okay
3 Views