fix: address lab2 review feedback

This commit is contained in:
Fedoroff
2026-10-27 20:03:08 +03:00
parent c251f2cb7d
commit f08011385a
11 changed files with 280 additions and 82 deletions
+14
View File
@@ -199,3 +199,17 @@ func (s *AuthStore) RevokeSession(
}
return nil
}
// GetActiveSessionUserID is the authoritative expiry/revocation check.
// Redis only caches the public user profile; it never grants access on its own.
func (s *AuthStore) GetActiveSessionUserID(ctx context.Context, token string) (uuid.UUID, error) {
var userID uuid.UUID
err := s.pool.QueryRow(ctx, `SELECT user_id FROM sessions WHERE token_hash=$1 AND expires_at>NOW()`, tokenHash(token)).Scan(&userID)
if errors.Is(err, pgx.ErrNoRows) {
return uuid.Nil, ErrSessionNotFound
}
if err != nil {
return uuid.Nil, fmt.Errorf("validate session: %w", err)
}
return userID, nil
}