Can you get the session id for a newly created ses...
# ktor
Can you get the session id for a newly created session? Configuration:
Copy code
install(Sessions) {
        header<UserSession>("user_session", SessionStorageMemory())
Once we have a session running and the header is sent in - then I can get the session ID simply from
. But - I would like to get the ID in the route block where the session gets set the first time:
Copy code

// get session ID here
call.sessionId is null at this point (perhaps unsurprisingly - its not on the call at this point). Is it possible to get the session ID at this point?
Unfortunately, it's not possible. Why do you need to get the session ID right after setting a value?
Because I'm storing the result of an auth flow that takes me out of my site (basic oauth2) and then redirects back. This is in the route block that handles that callback. From there I need a way to get back into the SPA that I started with so I was thinking of redirecting to the root URL of the SPA. But the SPA will need that id to send in subsequent calls.
Note that the auth I get back from the auth flow is not something I want the frontend to have direct access to. So I was storing it in server side session
Worked around by dropping session but using a cache keyed on info from the users local JWT (using a locally generated JWT) to find the remote token 🙂 More or less equivalent to the built in session stuff except that I control the ID used 🙂
👍 1