Skip to content

Commit

Permalink
fix NewAuthenticatedUserSession
Browse files Browse the repository at this point in the history
  • Loading branch information
vnxx committed Jul 8, 2024
1 parent 360237e commit 139dfc2
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions support/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,31 @@ func (s *support) NewAuthenticatedUserSession(user interface{}) error {
return err
}

// before reset the session, get redirection from the session, then save redirection to the new session
// before destroy the session, get redirection from the session, then save redirection to the new session
var redirection string
_redirection := session.Get(constant.KeyRedirection + session.ID())
if _redirection != nil {
redirection = _redirection.(string)
}
session.Destroy()

session.Reset()
session.SetExpiry((time.Hour * 24) * 7)
// get new session
sessionNew, err := s.session.Get(s.GetCtx())
if err != nil {
return err
}

sessionNew.SetExpiry((time.Hour * 24) * 7)

if redirection != "" {
session.Set(constant.KeyRedirection+session.ID(), redirection)
sessionNew.Set(constant.KeyRedirection+sessionNew.ID(), redirection)
}

sessionKey := constant.KeyAuth + session.ID()
sessionKey := constant.KeyAuth + sessionNew.ID()
buf, _ := json.Marshal(user)
session.Set(sessionKey, buf)
sessionNew.Set(sessionKey, buf)

if err := session.Save(); err != nil {
if err := sessionNew.Save(); err != nil {
return err
}

Expand Down

0 comments on commit 139dfc2

Please sign in to comment.