Упростить ошибки сессий, логировать миграции и тестировать с рабочим клиентом Valkey
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user