Golang Gorilla / Session

I am trying to create a simple web application with a username.

I found this feature in another post here.

func initSession(r *http.Request) *sessions.Session {
    session, _ := store.Get(r, "mBoxStore")
    if session.IsNew {
        session.Options.Domain = "localhost"
        session.Options.MaxAge = 10
        session.Options.HttpOnly = false
        session.Options.Secure = false
        log.Println("Create New Session (cookie)")
    } else {
        log.Println("Use Old Session (old cookie)")
    }
    return session
}

The cookie expires after 10 seconds, but when I reload the page after, for example, 1 Minute it uses the old (expired) cookie.

In my browser (Firefox) I see a cookie with an expiration date.

I think he should create a new session with a new cookie, or is it wrong?

any advice?

+4
source share
1 answer

, Use Old Session (old cookie), , cookie. , cookie (isNew == false) Options , , . MaxAge 86400 * 30 ( ).

:

  • cookie ( localhost)
  • cookie - + 10
  • 10 .
  • - cookie.
  • cookie (.. 10 )
  • , + 1 ( ).

, . , cookie (.. _csrf_token 4 ).

, , , , . , / cookie.

+4

Source: https://habr.com/ru/post/1527215/


All Articles