MCPcopy
hub / github.com/mudler/LocalAI / ValidateSession

Function ValidateSession

core/http/auth/session.go:50–61  ·  view source on GitHub ↗

ValidateSession hashes the plaintext token and looks up the session. Returns the associated user and session, or (nil, nil) if not found/expired.

(db *gorm.DB, token, hmacSecret string)

Source from the content-addressed store, hash-verified

48// ValidateSession hashes the plaintext token and looks up the session.
49// Returns the associated user and session, or (nil, nil) if not found/expired.
50func ValidateSession(db *gorm.DB, token, hmacSecret string) (*User, *Session) {
51 hash := HashAPIKey(token, hmacSecret)
52
53 var session Session
54 if err := db.Preload("User").Where("id = ? AND expires_at > ?", hash, time.Now()).First(&session).Error; err != nil {
55 return nil, nil
56 }
57 if session.User.Status != StatusActive {
58 return nil, nil
59 }
60 return &session.User, &session
61}
62
63// DeleteSession removes a session by hashing the plaintext token.
64func DeleteSession(db *gorm.DB, token, hmacSecret string) error {

Callers 3

session_test.goFile · 0.92
auth_test.goFile · 0.92
tryAuthenticateFunction · 0.85

Calls 2

HashAPIKeyFunction · 0.85
PreloadMethod · 0.80

Tested by

no test coverage detected