fix: persist login sessions for workbench auth

This commit is contained in:
richjohnrambo
2026-09-15 10:23:47 +08:00
parent ef8091d805
commit 9ec5da5b02
3 changed files with 55 additions and 1 deletions
+16 -1
View File
@@ -1317,7 +1317,22 @@ func (s *Session) onLogin(msgID string, timestamp time.Time, rec *auth.Rec, miss
// GenSecret fails only if tokenLifetime is < 0. It can't be < 0 here,
// otherwise login would have failed earlier.
rec.Features = features
params["token"], params["expires"], _ = store.Store.GetLogicalAuthHandler("token").GenSecret(rec)
token, expires, _ := store.Store.GetLogicalAuthHandler("token").GenSecret(rec)
params["token"], params["expires"] = token, expires
if !s.uid.IsZero() && features&auth.FeatureNoLogin == 0 {
if enabled, err := store.StoreLoginSession(token, store.LoginSession{
UserID: store.DecodeUid(rec.Uid),
TenantID: int64(s.tenantID),
TenantCode: s.tenantCode,
DeviceID: s.deviceID,
AuthLevel: rec.AuthLevel.String(),
State: "active",
ExpiresAt: expires.Format(time.RFC3339),
IssuedAt: time.Now().UTC().Format(time.RFC3339),
}, time.Until(expires)); enabled && err != nil {
logs.Warn.Println("s.onLogin: failed to store login session", rec.Uid, err, s.sid)
}
}
reply.Ctrl.Params = params
return reply