forked from mtusi2026/mtusi2026lab3
refactor: разделил приложение на domain application adapters и HTTP DTO
This commit is contained in:
@@ -7,8 +7,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"mtusi2026lab3/internal/domain"
|
||||
"mtusi2026lab3/internal/security"
|
||||
"mtusi2026lab3/internal/store"
|
||||
"mtusi2026lab3/internal/transport/http/response"
|
||||
)
|
||||
|
||||
@@ -20,10 +18,10 @@ const (
|
||||
)
|
||||
|
||||
type SessionAuthenticator interface {
|
||||
GetUserBySession(
|
||||
Authenticate(
|
||||
ctx context.Context,
|
||||
tokenHash []byte,
|
||||
) (domain.User, error)
|
||||
token string,
|
||||
) (domain.User, []byte, error)
|
||||
}
|
||||
|
||||
func RequireAuth(
|
||||
@@ -39,13 +37,11 @@ func RequireAuth(
|
||||
return
|
||||
}
|
||||
|
||||
tokenHash := security.HashSessionToken(token)
|
||||
|
||||
user, err := authenticator.GetUserBySession(
|
||||
user, tokenHash, err := authenticator.Authenticate(
|
||||
r.Context(),
|
||||
tokenHash,
|
||||
token,
|
||||
)
|
||||
if errors.Is(err, store.ErrNotFound) {
|
||||
if errors.Is(err, domain.ErrNotFound) {
|
||||
writeBearerUnauthorized(w, requestID)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user