InitSession creates the cookie store. It depends on the keychain already being loaded.
()
| 34 | // InitSession creates the cookie store. It depends on the keychain already |
| 35 | // being loaded. |
| 36 | func (app *App) InitSession() { |
| 37 | // Register complex data types we'll be storing in cookies |
| 38 | gob.Register(&User{}) |
| 39 | |
| 40 | // Create the cookie store |
| 41 | store := sessions.NewCookieStore(app.keys.CookieAuthKey, app.keys.CookieKey) |
| 42 | store.Options = &sessions.Options{ |
| 43 | Path: "/", |
| 44 | MaxAge: sessionLength, |
| 45 | HttpOnly: true, |
| 46 | Secure: strings.HasPrefix(app.cfg.App.Host, "https://"), |
| 47 | } |
| 48 | if store.Options.Secure { |
| 49 | store.Options.SameSite = http.SameSiteNoneMode |
| 50 | } |
| 51 | app.sessionStore = store |
| 52 | } |
| 53 | |
| 54 | func getSessionFlashes(app *App, w http.ResponseWriter, r *http.Request, session *sessions.Session) ([]string, error) { |
| 55 | var err error |