Упростить ошибки сессий, логировать миграции и тестировать с рабочим клиентом Valkey

This commit is contained in:
2026-10-06 15:46:01 +03:00
parent 405fb07608
commit f9850a36c4
7 changed files with 39 additions and 34 deletions
+4 -9
View File
@@ -2,7 +2,6 @@ package auth
import (
"context"
"errors"
"time"
"github.com/google/uuid"
@@ -53,15 +52,11 @@ func (s *Service) Login(ctx context.Context, username, password string) (Issued,
return Issued{Token: token, ExpiresAt: expiresAt, User: u}, nil
}
// Authenticate returns the owner of the token's live session. A store
// failure is returned as is, never as ErrUnauthenticated: an outage must not
// look like a bad token to the client.
// Authenticate returns the owner of the token's live session or
// ErrUnauthenticated. A store failure stays an unavailability, never
// ErrUnauthenticated: an outage must not look like a bad token to the client.
func (s *Service) Authenticate(ctx context.Context, token string) (uuid.UUID, error) {
id, err := s.sessions.UserID(ctx, HashToken(token))
if errors.Is(err, ErrSessionNotFound) {
return uuid.Nil, ErrUnauthenticated
}
return id, err
return s.sessions.UserID(ctx, HashToken(token))
}
func (s *Service) Logout(ctx context.Context, token string) error {