feat(auth): implement user and device authentication

This commit is contained in:
QiuSW
2026-07-26 15:18:48 +08:00
parent c5d3b215ff
commit 49db5b8305
66 changed files with 6216 additions and 271 deletions
@@ -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)
}
}