feat: added logout handler

This commit is contained in:
2026-08-21 13:49:47 +02:00
parent a5860c5079
commit 5e23d9cc9f
5 changed files with 102 additions and 2 deletions
+12
View File
@@ -19,6 +19,8 @@ type AuthRepository interface {
GetUserByEmail(ctx context.Context, email string) (*AuthUser, error)
StoreRefreshToken(ctx context.Context, userID string, tokenHash string, expiresAt time.Time) error
ConsumeRefreshToken(ctx context.Context, tokenHash string) (string, error)
RevokeRefreshToken(ctx context.Context, tokenHash string) error
RevokeRefreshTokens(ctx context.Context, userID string) error
}
type AuthService struct {
@@ -102,6 +104,16 @@ func (s *AuthService) Refresh(ctx context.Context, refreshToken string) (TokenPa
return s.issueTokens(ctx, authUser)
}
func (s *AuthService) Logout(ctx context.Context, refreshToken string) error {
tokenHash := hashToken(refreshToken)
return s.repo.RevokeRefreshToken(ctx, tokenHash)
}
func (s *AuthService) LogoutAllDevices(ctx context.Context, userID string) error {
return s.repo.RevokeRefreshTokens(ctx, userID)
}
type JWTClaims struct {
UserID string `json:"user_id"`
Email string `json:"email"`