Fixed cookie not being properly extended

This commit is contained in:
Jan Zípek 2022-08-28 08:38:22 +02:00
parent 6f85f4a45b
commit f767610f22
1 changed files with 11 additions and 2 deletions

View File

@ -19,6 +19,7 @@ func (s *AuthService) FromContext(ctx *gin.Context) (*SessionItem, error) {
return nil, err
}
s.setCookieFromSession(ctx, session)
s.ctx.Services.Sessions.Extend(session)
return session, nil
@ -31,7 +32,7 @@ func (s *AuthService) Login(ctx *gin.Context) error {
return err
}
ctx.SetCookie(SESSION_ID, session.Id, int(time.Duration(time.Hour*24).Seconds()), "/", "", true, true)
s.setCookieFromSession(ctx, session)
return nil
}
@ -47,11 +48,19 @@ func (s *AuthService) Logout(ctx *gin.Context) error {
return err
}
ctx.SetCookie(SESSION_ID, "", 0, "/", "", true, true)
s.clearCookie(ctx)
return nil
}
func (s *AuthService) clearCookie(ctx *gin.Context) {
ctx.SetCookie(SESSION_ID, "", 0, "/", "", false, true)
}
func (s *AuthService) setCookieFromSession(ctx *gin.Context, session *SessionItem) {
ctx.SetCookie(SESSION_ID, session.Id, int(time.Duration(time.Hour*24).Seconds()), "/", "", false, true)
}
func (s *AuthService) getSessionFromContext(ctx *gin.Context) (*SessionItem, error) {
cookie, err := ctx.Cookie(SESSION_ID)