alexedwards / scs

HTTP Session Management for Go
MIT License
2.09k stars 166 forks source link

Get session token from context #75

Closed eduardhasanaj closed 4 years ago

eduardhasanaj commented 4 years ago

Sorry for writing again about expire session time. I am in need to retrieve session token from context so I can register it to an expiry system. Is there any workaround? Will break anything if i call commit in the handler. I know that after request finishes commit will be called again. Best wishes

alexedwards commented 4 years ago

Yes, there is no problem with calling commit multiple times during the same request. It's the right way to get the session token that will be used.

eduardhasanaj commented 4 years ago

Thanks for the confirmation! I am closing this issue.

jherman commented 4 years ago

Sorry for reviving this. I'm also attempting to get the token/session id, but I seem to get a new ID on each page refresh. This is different than what Chrome reports me as the session ID.

I'm using your example code, but added the following handler:

func sessionHandler(w http.ResponseWriter, r *http.Request) {
    ctx := r.Context()

    // sessionManager.RenewToken(ctx)

    id, _, _ := sessionManager.Commit(ctx)

    io.WriteString(w, id)
}

This is what I see when I reach that endpoint:

image

My expectations were that these numbers would match, but they don't. Any idea what I'm doing wrong?