refactor to improve database operability in hwsauth
This commit is contained in:
@@ -9,8 +9,8 @@ import (
|
||||
)
|
||||
|
||||
// Check the cookies for token strings and attempt to authenticate them
|
||||
func (auth *Authenticator[T]) getAuthenticatedUser(
|
||||
tx DBTransaction,
|
||||
func (auth *Authenticator[T, TX]) getAuthenticatedUser(
|
||||
tx TX,
|
||||
w http.ResponseWriter,
|
||||
r *http.Request,
|
||||
) (authenticatedModel[T], error) {
|
||||
@@ -20,10 +20,10 @@ func (auth *Authenticator[T]) getAuthenticatedUser(
|
||||
return authenticatedModel[T]{}, errors.New("No token strings provided")
|
||||
}
|
||||
// Attempt to parse the access token
|
||||
aT, err := auth.tokenGenerator.ValidateAccess(tx, atStr)
|
||||
aT, err := auth.tokenGenerator.ValidateAccess(jwt.DBTransaction(tx), atStr)
|
||||
if err != nil {
|
||||
// Access token invalid, attempt to parse refresh token
|
||||
rT, err := auth.tokenGenerator.ValidateRefresh(tx, rtStr)
|
||||
rT, err := auth.tokenGenerator.ValidateRefresh(jwt.DBTransaction(tx), rtStr)
|
||||
if err != nil {
|
||||
return authenticatedModel[T]{}, errors.Wrap(err, "auth.tokenGenerator.ValidateRefresh")
|
||||
}
|
||||
@@ -41,7 +41,7 @@ func (auth *Authenticator[T]) getAuthenticatedUser(
|
||||
}
|
||||
|
||||
// Access token valid
|
||||
model, err := auth.load(tx, aT.SUB)
|
||||
model, err := auth.load(r.Context(), tx, aT.SUB)
|
||||
if err != nil {
|
||||
return authenticatedModel[T]{}, errors.Wrap(err, "auth.load")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user