feat: implement TASK-WP1-02 login sessions
This commit is contained in:
@@ -10,22 +10,42 @@ export type RegistrationErrorReason =
|
||||
| "privacy_consent_required"
|
||||
| "privacy_notice_version_invalid"
|
||||
| "profile_invalid"
|
||||
| "idempotency_conflict";
|
||||
| "idempotency_conflict"
|
||||
| "registration_login_required"
|
||||
| "login_registration_required"
|
||||
| "account_suspended"
|
||||
| "login_admin_required"
|
||||
| "resend_too_soon"
|
||||
| "too_many_attempts"
|
||||
| "csrf_invalid"
|
||||
| "session_invalid";
|
||||
|
||||
export type RegistrationErrorCode =
|
||||
| "REGISTRATION_REJECTED"
|
||||
| "REGISTRATION_REQUEST_INVALID"
|
||||
| "IDEMPOTENCY_KEY_CONFLICT";
|
||||
| "IDEMPOTENCY_KEY_CONFLICT"
|
||||
| "AUTH_ENTRY_REJECTED"
|
||||
| "AUTH_RATE_LIMITED"
|
||||
| "AUTH_CSRF_INVALID"
|
||||
| "AUTH_SESSION_INVALID";
|
||||
|
||||
export class RegistrationError extends Error {
|
||||
readonly code: RegistrationErrorCode;
|
||||
readonly httpStatus: 400 | 409;
|
||||
readonly httpStatus: 400 | 401 | 403 | 409 | 429;
|
||||
readonly reason: RegistrationErrorReason;
|
||||
|
||||
constructor(code: RegistrationErrorCode, reason: RegistrationErrorReason) {
|
||||
super(code);
|
||||
this.code = code;
|
||||
this.httpStatus = code === "REGISTRATION_REQUEST_INVALID" ? 400 : 409;
|
||||
this.httpStatus = code === "REGISTRATION_REQUEST_INVALID"
|
||||
? 400
|
||||
: code === "AUTH_SESSION_INVALID"
|
||||
? 401
|
||||
: code === "AUTH_CSRF_INVALID"
|
||||
? 403
|
||||
: code === "AUTH_RATE_LIMITED"
|
||||
? 429
|
||||
: 409;
|
||||
this.reason = reason;
|
||||
}
|
||||
}
|
||||
@@ -44,6 +64,14 @@ export function registrationFieldError(reason: RegistrationErrorReason) {
|
||||
privacy_notice_version_invalid: { field: "privacy_notice_version", message_key: "auth.privacy.notice_version_invalid" },
|
||||
profile_invalid: { field: "profile", message_key: "auth.profile.invalid" },
|
||||
stage_limit_reached: { field: "invite_code", message_key: "auth.registration.stage_limit_reached" },
|
||||
registration_login_required: { field: "email", message_key: "auth.registration.login_required" },
|
||||
login_registration_required: { field: "email", message_key: "auth.login.registration_required" },
|
||||
account_suspended: { field: "email", message_key: "auth.account.suspended" },
|
||||
login_admin_required: { field: "email", message_key: "auth.login.admin_required" },
|
||||
resend_too_soon: { field: "verification_code", message_key: "auth.challenge.resend_too_soon" },
|
||||
too_many_attempts: { field: "verification_code", message_key: "auth.challenge.too_many_attempts" },
|
||||
csrf_invalid: { field: "csrf_token", message_key: "auth.csrf.invalid" },
|
||||
session_invalid: { field: "session", message_key: "auth.session.invalid" },
|
||||
};
|
||||
return entries[reason];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user