fix(session): Fixed the session status update logic. (#9296)

- Removed the error returned when the session status is `SessionInactive`.
- Updated the `LastActive` field of the session to always record the current time.
pull/9299/head
千石 2025-08-28 09:57:13 +08:00 committed by GitHub
parent de09ba08b6
commit 3bf0af1e68
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 4 deletions

View File

@ -25,11 +25,9 @@ func Handle(userID uint, deviceKey, ua, ip string) error {
now := time.Now().Unix() now := time.Now().Unix()
sess, err := db.GetSession(userID, deviceKey) sess, err := db.GetSession(userID, deviceKey)
if err == nil { if err == nil {
if sess.Status == model.SessionInactive { // reactivate existing session if it was inactive
return errors.WithStack(errs.SessionInactive)
}
sess.LastActive = now
sess.Status = model.SessionActive sess.Status = model.SessionActive
sess.LastActive = now
sess.UserAgent = ua sess.UserAgent = ua
sess.IP = ip sess.IP = ip
return db.UpsertSession(sess) return db.UpsertSession(sess)