forked from mtusi2026/mtusi2026lab2
fix: address lab2 review feedback
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user