@withstudiocms/auth-kit
Version:
Utilities for managing authentication
62 lines (61 loc) • 1.72 kB
JavaScript
import { Data, Effect } from "@withstudiocms/effect";
class EncryptionError extends Data.TaggedError("EncryptionError") {
}
class DecryptionError extends Data.TaggedError("DecryptionError") {
}
class PasswordError extends Data.TaggedError("PasswordError") {
}
class CheckIfUnsafeError extends Data.TaggedError("CheckIfUnsafeError") {
}
class SessionError extends Data.TaggedError("SessionError") {
}
class UserError extends Data.TaggedError("UserError") {
}
const useEncryptionError = (_try) => Effect.try({
try: _try,
catch: (cause) => new EncryptionError({ cause })
});
const useDecryptionError = (_try) => Effect.try({
try: _try,
catch: (cause) => new DecryptionError({ cause })
});
const usePasswordError = (_try) => Effect.try({
try: _try,
catch: (cause) => new PasswordError({ cause })
});
const useSessionError = (_try) => Effect.try({
try: _try,
catch: (cause) => new SessionError({ cause })
});
const useSessionErrorPromise = (_try) => Effect.tryPromise({
try: _try,
catch: (cause) => new SessionError({ cause })
});
const useUnsafeCheckError = (_try, prefix) => Effect.try({
try: _try,
catch: (cause) => new CheckIfUnsafeError({ message: `${prefix}: ${cause}` })
});
const useUserError = (_try) => Effect.try({
try: _try,
catch: (cause) => new UserError({ cause })
});
const useUserErrorPromise = (_try) => Effect.tryPromise({
try: _try,
catch: (cause) => new UserError({ cause })
});
export {
CheckIfUnsafeError,
DecryptionError,
EncryptionError,
PasswordError,
SessionError,
UserError,
useDecryptionError,
useEncryptionError,
usePasswordError,
useSessionError,
useSessionErrorPromise,
useUnsafeCheckError,
useUserError,
useUserErrorPromise
};