feat(auth): implement user and device authentication
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package usecase
|
||||
|
||||
import "errors"
|
||||
|
||||
const (
|
||||
ErrorKindUnauthorized ErrorKind = "UNAUTHORIZED"
|
||||
ErrorKindForbidden ErrorKind = "FORBIDDEN"
|
||||
)
|
||||
|
||||
func wrapAuthRepositoryError(err error) error {
|
||||
switch {
|
||||
case errors.Is(err, ErrAuthCredentials):
|
||||
return newError(
|
||||
ErrorKindUnauthorized,
|
||||
"AUTH_INVALID_CREDENTIALS",
|
||||
"invalid credentials",
|
||||
err,
|
||||
)
|
||||
case errors.Is(err, ErrAuthDisabled):
|
||||
return newError(
|
||||
ErrorKindForbidden,
|
||||
"AUTH_ACCOUNT_OR_DEVICE_DISABLED",
|
||||
"account or device is disabled",
|
||||
err,
|
||||
)
|
||||
case errors.Is(err, ErrAuthForbidden):
|
||||
return newError(
|
||||
ErrorKindForbidden,
|
||||
"AUTH_FORBIDDEN",
|
||||
"identity is not allowed to perform this operation",
|
||||
err,
|
||||
)
|
||||
case errors.Is(err, ErrAuthExpired):
|
||||
return newError(
|
||||
ErrorKindUnauthorized,
|
||||
"AUTH_SESSION_EXPIRED",
|
||||
"session expired",
|
||||
err,
|
||||
)
|
||||
case errors.Is(err, ErrAuthRevoked):
|
||||
return newError(
|
||||
ErrorKindUnauthorized,
|
||||
"AUTH_INVALID_TOKEN",
|
||||
"invalid token",
|
||||
err,
|
||||
)
|
||||
case errors.Is(err, ErrAuthConflict):
|
||||
return newError(
|
||||
ErrorKindConflict,
|
||||
"AUTH_RESOURCE_CONFLICT",
|
||||
"authentication resource already exists",
|
||||
err,
|
||||
)
|
||||
default:
|
||||
return wrapRepositoryError(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user