[WEB-1319] fix: handled magic sign_in and sign_up error codes in authentication (#4518)

* dev: differentiate error codes for magic code

* fix: handled auth error_codes for magic_sign_in and magic_sign_up

---------

Co-authored-by: pablohashescobar <nikhilschacko@gmail.com>
This commit is contained in:
guru_sainath 2024-05-20 12:23:48 +05:30 committed by GitHub
parent 603ebeb123
commit 2138257da0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 261 additions and 98 deletions

View File

@ -25,9 +25,12 @@ AUTHENTICATION_ERROR_CODES = {
"INVALID_EMAIL_MAGIC_SIGN_IN": 5080, "INVALID_EMAIL_MAGIC_SIGN_IN": 5080,
"MAGIC_SIGN_IN_EMAIL_CODE_REQUIRED": 5085, "MAGIC_SIGN_IN_EMAIL_CODE_REQUIRED": 5085,
# Both Sign in and Sign up for magic # Both Sign in and Sign up for magic
"INVALID_MAGIC_CODE": 5090, "INVALID_MAGIC_CODE_SIGN_IN": 5090,
"EXPIRED_MAGIC_CODE": 5095, "INVALID_MAGIC_CODE_SIGN_UP": 5092,
"EMAIL_CODE_ATTEMPT_EXHAUSTED": 5100, "EXPIRED_MAGIC_CODE_SIGN_IN": 5095,
"EXPIRED_MAGIC_CODE_SIGN_UP": 5097,
"EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_IN": 5100,
"EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_UP": 5102,
# Oauth # Oauth
"GOOGLE_NOT_CONFIGURED": 5105, "GOOGLE_NOT_CONFIGURED": 5105,
"GITHUB_NOT_CONFIGURED": 5110, "GITHUB_NOT_CONFIGURED": 5110,

View File

@ -13,6 +13,7 @@ from plane.authentication.adapter.error import (
AUTHENTICATION_ERROR_CODES, AUTHENTICATION_ERROR_CODES,
AuthenticationException, AuthenticationException,
) )
from plane.db.models import User
class MagicCodeProvider(CredentialAdapter): class MagicCodeProvider(CredentialAdapter):
@ -86,13 +87,23 @@ class MagicCodeProvider(CredentialAdapter):
current_attempt = data["current_attempt"] + 1 current_attempt = data["current_attempt"] + 1
if data["current_attempt"] > 2: if data["current_attempt"] > 2:
raise AuthenticationException( email = str(self.key).replace("magic_", "", 1)
error_code=AUTHENTICATION_ERROR_CODES[ if User.objects.exists(email=email):
"EMAIL_CODE_ATTEMPT_EXHAUSTED" raise AuthenticationException(
], error_code=AUTHENTICATION_ERROR_CODES[
error_message="EMAIL_CODE_ATTEMPT_EXHAUSTED", "EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_IN"
payload={"email": self.key}, ],
) error_message="EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_IN",
payload={"email": str(email)},
)
else:
raise AuthenticationException(
error_code=AUTHENTICATION_ERROR_CODES[
"EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_UP"
],
error_message="EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_UP",
payload={"email": self.key},
)
value = { value = {
"current_attempt": current_attempt, "current_attempt": current_attempt,
@ -132,18 +143,38 @@ class MagicCodeProvider(CredentialAdapter):
ri.delete(self.key) ri.delete(self.key)
return return
else: else:
email = str(self.key).replace("magic_", "", 1)
if User.objects.exists(email=email):
raise AuthenticationException(
error_code=AUTHENTICATION_ERROR_CODES[
"INVALID_MAGIC_CODE_SIGN_IN"
],
error_message="INVALID_MAGIC_CODE_SIGN_IN",
payload={"email": str(email)},
)
else:
raise AuthenticationException(
error_code=AUTHENTICATION_ERROR_CODES[
"INVALID_MAGIC_CODE_SIGN_UP"
],
error_message="INVALID_MAGIC_CODE_SIGN_UP",
payload={"email": str(email)},
)
else:
email = str(self.key).replace("magic_", "", 1)
if User.objects.exists(email=email):
raise AuthenticationException( raise AuthenticationException(
error_code=AUTHENTICATION_ERROR_CODES[ error_code=AUTHENTICATION_ERROR_CODES[
"INVALID_MAGIC_CODE" "EXPIRED_MAGIC_CODE_SIGN_IN"
], ],
error_message="INVALID_MAGIC_CODE", error_message="EXPIRED_MAGIC_CODE_SIGN_IN",
payload={"email": str(email)},
)
else:
raise AuthenticationException(
error_code=AUTHENTICATION_ERROR_CODES[
"EXPIRED_MAGIC_CODE_SIGN_UP"
],
error_message="EXPIRED_MAGIC_CODE_SIGN_UP",
payload={"email": str(email)}, payload={"email": str(email)},
) )
else:
magic_key = str(self.key)
email = magic_key.replace("magic_", "", 1)
raise AuthenticationException(
error_code=AUTHENTICATION_ERROR_CODES["EXPIRED_MAGIC_CODE"],
error_message="EXPIRED_MAGIC_CODE",
payload={"email": str(email)},
)

View File

@ -49,19 +49,34 @@ export const AuthRoot: FC = observer(() => {
if (error_code) { if (error_code) {
const errorhandler = authErrorHandler(error_code?.toString() as EAuthenticationErrorCodes); const errorhandler = authErrorHandler(error_code?.toString() as EAuthenticationErrorCodes);
if (errorhandler) { if (errorhandler) {
if (errorhandler.code === EAuthenticationErrorCodes.AUTHENTICATION_FAILED_SIGN_IN) {
setAuthMode(EAuthModes.SIGN_IN);
setAuthStep(EAuthSteps.PASSWORD);
}
if (errorhandler.code === EAuthenticationErrorCodes.AUTHENTICATION_FAILED_SIGN_UP) {
setAuthMode(EAuthModes.SIGN_UP);
setAuthStep(EAuthSteps.PASSWORD);
}
if ( if (
[ [
EAuthenticationErrorCodes.AUTHENTICATION_FAILED_SIGN_IN, EAuthenticationErrorCodes.INVALID_MAGIC_CODE_SIGN_IN,
EAuthenticationErrorCodes.AUTHENTICATION_FAILED_SIGN_UP, EAuthenticationErrorCodes.EXPIRED_MAGIC_CODE_SIGN_IN,
EAuthenticationErrorCodes.EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_IN,
].includes(errorhandler.code) ].includes(errorhandler.code)
) ) {
setAuthStep(EAuthSteps.PASSWORD); setAuthMode(EAuthModes.SIGN_IN);
if (
[EAuthenticationErrorCodes.INVALID_MAGIC_CODE, EAuthenticationErrorCodes.EXPIRED_MAGIC_CODE].includes(
errorhandler.code
)
)
setAuthStep(EAuthSteps.UNIQUE_CODE); setAuthStep(EAuthSteps.UNIQUE_CODE);
}
if (
[
EAuthenticationErrorCodes.INVALID_MAGIC_CODE_SIGN_UP,
EAuthenticationErrorCodes.EXPIRED_MAGIC_CODE_SIGN_UP,
EAuthenticationErrorCodes.EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_UP,
].includes(errorhandler.code)
) {
setAuthMode(EAuthModes.SIGN_UP);
setAuthStep(EAuthSteps.UNIQUE_CODE);
}
setErrorInfo(errorhandler); setErrorInfo(errorhandler);
} }
} }

View File

@ -21,42 +21,57 @@ export enum EErrorAlertType {
export enum EAuthenticationErrorCodes { export enum EAuthenticationErrorCodes {
// Global // Global
INSTANCE_NOT_CONFIGURED = "5000", INSTANCE_NOT_CONFIGURED = "5000",
SIGNUP_DISABLED = "5001", INVALID_EMAIL = "5005",
INVALID_PASSWORD = "5002", // Password strength validation EMAIL_REQUIRED = "5010",
SMTP_NOT_CONFIGURED = "5007", SIGNUP_DISABLED = "5015",
// email check // Password strength
INVALID_EMAIL = "5012", INVALID_PASSWORD = "5020",
EMAIL_REQUIRED = "5013", SMTP_NOT_CONFIGURED = "5025",
// Sign Up // Sign Up
USER_ACCOUNT_DEACTIVATED = "5019", USER_ALREADY_EXIST = "5030",
USER_ALREADY_EXIST = "5003", AUTHENTICATION_FAILED_SIGN_UP = "5035",
REQUIRED_EMAIL_PASSWORD_SIGN_UP = "5015", REQUIRED_EMAIL_PASSWORD_SIGN_UP = "5040",
AUTHENTICATION_FAILED_SIGN_UP = "5006", INVALID_EMAIL_SIGN_UP = "5045",
INVALID_EMAIL_SIGN_UP = "5017", INVALID_EMAIL_MAGIC_SIGN_UP = "5050",
MAGIC_SIGN_UP_EMAIL_CODE_REQUIRED = "5023", MAGIC_SIGN_UP_EMAIL_CODE_REQUIRED = "5055",
// Sign In // Sign In
USER_DOES_NOT_EXIST = "5004", USER_ACCOUNT_DEACTIVATED = "5019",
REQUIRED_EMAIL_PASSWORD_SIGN_IN = "5014", USER_DOES_NOT_EXIST = "5060",
AUTHENTICATION_FAILED_SIGN_IN = "5005", AUTHENTICATION_FAILED_SIGN_IN = "5065",
INVALID_EMAIL_SIGN_IN = "5016", REQUIRED_EMAIL_PASSWORD_SIGN_IN = "5070",
MAGIC_SIGN_IN_EMAIL_CODE_REQUIRED = "5022", INVALID_EMAIL_SIGN_IN = "5075",
INVALID_EMAIL_MAGIC_SIGN_IN = "5018", INVALID_EMAIL_MAGIC_SIGN_IN = "5080",
// Both Sign in and Sign up MAGIC_SIGN_IN_EMAIL_CODE_REQUIRED = "5085",
INVALID_MAGIC_CODE = "5008", // Both Sign in and Sign up for magic
EXPIRED_MAGIC_CODE = "5009", INVALID_MAGIC_CODE_SIGN_IN = "5090",
INVALID_MAGIC_CODE_SIGN_UP = "5092",
EXPIRED_MAGIC_CODE_SIGN_IN = "5095",
EXPIRED_MAGIC_CODE_SIGN_UP = "5097",
EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_IN = "5100",
EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_UP = "5102",
// Oauth // Oauth
GOOGLE_NOT_CONFIGURED = "5010", GOOGLE_NOT_CONFIGURED = "5105",
GITHUB_NOT_CONFIGURED = "5011", GITHUB_NOT_CONFIGURED = "5110",
GOOGLE_OAUTH_PROVIDER_ERROR = "5021", GOOGLE_OAUTH_PROVIDER_ERROR = "5115",
GITHUB_OAUTH_PROVIDER_ERROR = "5020", GITHUB_OAUTH_PROVIDER_ERROR = "5120",
// Reset Password // Reset Password
INVALID_PASSWORD_TOKEN = "5024", INVALID_PASSWORD_TOKEN = "5125",
EXPIRED_PASSWORD_TOKEN = "5025", EXPIRED_PASSWORD_TOKEN = "5130",
// Change password // Change password
INCORRECT_OLD_PASSWORD = "5026", INCORRECT_OLD_PASSWORD = "5135",
INVALID_NEW_PASSWORD = "5027", MISSING_PASSWORD = "5138",
// set password INVALID_NEW_PASSWORD = "5140",
PASSWORD_ALREADY_SET = "5028", // used in the onboarding and set password page // set passowrd
PASSWORD_ALREADY_SET = "5145",
// Admin
ADMIN_ALREADY_EXIST = "5150",
REQUIRED_ADMIN_EMAIL_PASSWORD_FIRST_NAME = "5155",
INVALID_ADMIN_EMAIL = "5160",
INVALID_ADMIN_PASSWORD = "5165",
REQUIRED_ADMIN_EMAIL_PASSWORD = "5170",
ADMIN_AUTHENTICATION_FAILED = "5175",
ADMIN_USER_ALREADY_EXIST = "5180",
ADMIN_USER_DOES_NOT_EXIST = "5185",
} }
export type TAuthErrorInfo = { export type TAuthErrorInfo = {
@ -105,7 +120,7 @@ const errorCodeMessages: {
Your account is already registered.&nbsp; Your account is already registered.&nbsp;
<Link <Link
className="underline underline-offset-4 font-medium hover:font-bold transition-all" className="underline underline-offset-4 font-medium hover:font-bold transition-all"
href={`/accounts/sign-in${email ? `?email=${encodeURIComponent(email)}` : ``}`} href={`/sign-in${email ? `?email=${encodeURIComponent(email)}` : ``}`}
> >
Sign In Sign In
</Link> </Link>
@ -129,12 +144,15 @@ const errorCodeMessages: {
title: `Email and code required`, title: `Email and code required`,
message: () => `Email and code required. Please try again.`, message: () => `Email and code required. Please try again.`,
}, },
[EAuthenticationErrorCodes.INVALID_EMAIL_MAGIC_SIGN_UP]: {
title: `Invalid email`,
message: () => `Invalid email. Please try again.`,
},
// sign in // sign in
[EAuthenticationErrorCodes.USER_ACCOUNT_DEACTIVATED]: { [EAuthenticationErrorCodes.USER_ACCOUNT_DEACTIVATED]: {
title: `User account deactivated`, title: `User account deactivated`,
message: () => <div>Your account is deactivated. Please reach out to support@plane.so</div>, message: () => <div>Your account is deactivated. Contact support@plane.so.</div>,
}, },
[EAuthenticationErrorCodes.USER_DOES_NOT_EXIST]: { [EAuthenticationErrorCodes.USER_DOES_NOT_EXIST]: {
@ -174,11 +192,27 @@ const errorCodeMessages: {
}, },
// Both Sign in and Sign up // Both Sign in and Sign up
[EAuthenticationErrorCodes.INVALID_MAGIC_CODE]: { [EAuthenticationErrorCodes.INVALID_MAGIC_CODE_SIGN_IN]: {
title: `Authentication failed`, title: `Authentication failed`,
message: () => `Invalid magic code. Please try again.`, message: () => `Invalid magic code. Please try again.`,
}, },
[EAuthenticationErrorCodes.EXPIRED_MAGIC_CODE]: { [EAuthenticationErrorCodes.INVALID_MAGIC_CODE_SIGN_UP]: {
title: `Authentication failed`,
message: () => `Invalid magic code. Please try again.`,
},
[EAuthenticationErrorCodes.EXPIRED_MAGIC_CODE_SIGN_IN]: {
title: `Expired magic code`,
message: () => `Expired magic code. Please try again.`,
},
[EAuthenticationErrorCodes.EXPIRED_MAGIC_CODE_SIGN_UP]: {
title: `Expired magic code`,
message: () => `Expired magic code. Please try again.`,
},
[EAuthenticationErrorCodes.EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_IN]: {
title: `Expired magic code`,
message: () => `Expired magic code. Please try again.`,
},
[EAuthenticationErrorCodes.EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_UP]: {
title: `Expired magic code`, title: `Expired magic code`,
message: () => `Expired magic code. Please try again.`, message: () => `Expired magic code. Please try again.`,
}, },
@ -212,6 +246,10 @@ const errorCodeMessages: {
}, },
// Change password // Change password
[EAuthenticationErrorCodes.MISSING_PASSWORD]: {
title: `Password required`,
message: () => `Password required. Please try again.`,
},
[EAuthenticationErrorCodes.INCORRECT_OLD_PASSWORD]: { [EAuthenticationErrorCodes.INCORRECT_OLD_PASSWORD]: {
title: `Incorrect old password`, title: `Incorrect old password`,
message: () => `Incorrect old password. Please try again.`, message: () => `Incorrect old password. Please try again.`,
@ -226,26 +264,87 @@ const errorCodeMessages: {
title: `Password already set`, title: `Password already set`,
message: () => `Password already set. Please try again.`, message: () => `Password already set. Please try again.`,
}, },
// admin
[EAuthenticationErrorCodes.ADMIN_ALREADY_EXIST]: {
title: `Admin already exists`,
message: () => `Admin already exists. Please try again.`,
},
[EAuthenticationErrorCodes.REQUIRED_ADMIN_EMAIL_PASSWORD_FIRST_NAME]: {
title: `Email, password and first name required`,
message: () => `Email, password and first name required. Please try again.`,
},
[EAuthenticationErrorCodes.INVALID_ADMIN_EMAIL]: {
title: `Invalid admin email`,
message: () => `Invalid admin email. Please try again.`,
},
[EAuthenticationErrorCodes.INVALID_ADMIN_PASSWORD]: {
title: `Invalid admin password`,
message: () => `Invalid admin password. Please try again.`,
},
[EAuthenticationErrorCodes.REQUIRED_ADMIN_EMAIL_PASSWORD]: {
title: `Email and password required`,
message: () => `Email and password required. Please try again.`,
},
[EAuthenticationErrorCodes.ADMIN_AUTHENTICATION_FAILED]: {
title: `Authentication failed`,
message: () => `Authentication failed. Please try again.`,
},
[EAuthenticationErrorCodes.ADMIN_USER_ALREADY_EXIST]: {
title: `Admin user already exists`,
message: () => (
<div>
Admin user already exists.&nbsp;
<Link className="underline underline-offset-4 font-medium hover:font-bold transition-all" href={`/admin`}>
Sign In
</Link>
&nbsp;now.
</div>
),
},
[EAuthenticationErrorCodes.ADMIN_USER_DOES_NOT_EXIST]: {
title: `Admin user does not exist`,
message: () => (
<div>
Admin user does not exist.&nbsp;
<Link className="underline underline-offset-4 font-medium hover:font-bold transition-all" href={`/admin`}>
Sign In
</Link>
&nbsp;now.
</div>
),
},
}; };
export const authErrorHandler = ( export const authErrorHandler = (
errorCode: EAuthenticationErrorCodes, errorCode: EAuthenticationErrorCodes,
email?: string | undefined email?: string | undefined
): TAuthErrorInfo | undefined => { ): TAuthErrorInfo | undefined => {
const toastAlertErrorCodes = [ const bannerAlertErrorCodes = [
EAuthenticationErrorCodes.INSTANCE_NOT_CONFIGURED,
EAuthenticationErrorCodes.INVALID_EMAIL,
EAuthenticationErrorCodes.EMAIL_REQUIRED,
EAuthenticationErrorCodes.SIGNUP_DISABLED, EAuthenticationErrorCodes.SIGNUP_DISABLED,
EAuthenticationErrorCodes.INVALID_PASSWORD, EAuthenticationErrorCodes.INVALID_PASSWORD,
EAuthenticationErrorCodes.SMTP_NOT_CONFIGURED, EAuthenticationErrorCodes.SMTP_NOT_CONFIGURED,
EAuthenticationErrorCodes.INVALID_EMAIL, EAuthenticationErrorCodes.USER_ALREADY_EXIST,
EAuthenticationErrorCodes.EMAIL_REQUIRED,
EAuthenticationErrorCodes.AUTHENTICATION_FAILED_SIGN_UP, EAuthenticationErrorCodes.AUTHENTICATION_FAILED_SIGN_UP,
EAuthenticationErrorCodes.REQUIRED_EMAIL_PASSWORD_SIGN_UP,
EAuthenticationErrorCodes.INVALID_EMAIL_SIGN_UP, EAuthenticationErrorCodes.INVALID_EMAIL_SIGN_UP,
EAuthenticationErrorCodes.INVALID_EMAIL_MAGIC_SIGN_UP,
EAuthenticationErrorCodes.MAGIC_SIGN_UP_EMAIL_CODE_REQUIRED, EAuthenticationErrorCodes.MAGIC_SIGN_UP_EMAIL_CODE_REQUIRED,
EAuthenticationErrorCodes.USER_DOES_NOT_EXIST,
EAuthenticationErrorCodes.AUTHENTICATION_FAILED_SIGN_IN, EAuthenticationErrorCodes.AUTHENTICATION_FAILED_SIGN_IN,
EAuthenticationErrorCodes.REQUIRED_EMAIL_PASSWORD_SIGN_IN,
EAuthenticationErrorCodes.INVALID_EMAIL_SIGN_IN, EAuthenticationErrorCodes.INVALID_EMAIL_SIGN_IN,
EAuthenticationErrorCodes.INVALID_EMAIL_MAGIC_SIGN_IN, EAuthenticationErrorCodes.INVALID_EMAIL_MAGIC_SIGN_IN,
EAuthenticationErrorCodes.INVALID_MAGIC_CODE, EAuthenticationErrorCodes.MAGIC_SIGN_IN_EMAIL_CODE_REQUIRED,
EAuthenticationErrorCodes.EXPIRED_MAGIC_CODE, EAuthenticationErrorCodes.INVALID_MAGIC_CODE_SIGN_IN,
EAuthenticationErrorCodes.INVALID_MAGIC_CODE_SIGN_UP,
EAuthenticationErrorCodes.EXPIRED_MAGIC_CODE_SIGN_IN,
EAuthenticationErrorCodes.EXPIRED_MAGIC_CODE_SIGN_UP,
EAuthenticationErrorCodes.EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_IN,
EAuthenticationErrorCodes.EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_UP,
EAuthenticationErrorCodes.GOOGLE_NOT_CONFIGURED, EAuthenticationErrorCodes.GOOGLE_NOT_CONFIGURED,
EAuthenticationErrorCodes.GITHUB_NOT_CONFIGURED, EAuthenticationErrorCodes.GITHUB_NOT_CONFIGURED,
EAuthenticationErrorCodes.GOOGLE_OAUTH_PROVIDER_ERROR, EAuthenticationErrorCodes.GOOGLE_OAUTH_PROVIDER_ERROR,
@ -255,25 +354,17 @@ export const authErrorHandler = (
EAuthenticationErrorCodes.INCORRECT_OLD_PASSWORD, EAuthenticationErrorCodes.INCORRECT_OLD_PASSWORD,
EAuthenticationErrorCodes.INVALID_NEW_PASSWORD, EAuthenticationErrorCodes.INVALID_NEW_PASSWORD,
EAuthenticationErrorCodes.PASSWORD_ALREADY_SET, EAuthenticationErrorCodes.PASSWORD_ALREADY_SET,
]; EAuthenticationErrorCodes.ADMIN_ALREADY_EXIST,
const bannerAlertErrorCodes = [ EAuthenticationErrorCodes.REQUIRED_ADMIN_EMAIL_PASSWORD_FIRST_NAME,
EAuthenticationErrorCodes.INSTANCE_NOT_CONFIGURED, EAuthenticationErrorCodes.INVALID_ADMIN_EMAIL,
EAuthenticationErrorCodes.USER_ALREADY_EXIST, EAuthenticationErrorCodes.INVALID_ADMIN_PASSWORD,
EAuthenticationErrorCodes.USER_DOES_NOT_EXIST, EAuthenticationErrorCodes.REQUIRED_ADMIN_EMAIL_PASSWORD,
EAuthenticationErrorCodes.REQUIRED_EMAIL_PASSWORD_SIGN_UP, EAuthenticationErrorCodes.ADMIN_AUTHENTICATION_FAILED,
EAuthenticationErrorCodes.REQUIRED_EMAIL_PASSWORD_SIGN_IN, EAuthenticationErrorCodes.ADMIN_USER_ALREADY_EXIST,
EAuthenticationErrorCodes.MAGIC_SIGN_IN_EMAIL_CODE_REQUIRED, EAuthenticationErrorCodes.ADMIN_USER_DOES_NOT_EXIST,
EAuthenticationErrorCodes.USER_ACCOUNT_DEACTIVATED, EAuthenticationErrorCodes.USER_ACCOUNT_DEACTIVATED,
]; ];
if (toastAlertErrorCodes.includes(errorCode))
return {
type: EErrorAlertType.TOAST_ALERT,
code: errorCode,
title: errorCodeMessages[errorCode]?.title || "Error",
message: errorCodeMessages[errorCode]?.message(email) || "Something went wrong. Please try again.",
};
if (bannerAlertErrorCodes.includes(errorCode)) if (bannerAlertErrorCodes.includes(errorCode))
return { return {
type: EErrorAlertType.BANNER_ALERT, type: EErrorAlertType.BANNER_ALERT,

View File

@ -58,9 +58,14 @@ export const AuthRoot: FC<TAuthRoot> = observer((props) => {
) )
setAuthStep(EAuthSteps.PASSWORD); setAuthStep(EAuthSteps.PASSWORD);
if ( if (
[EAuthenticationErrorCodes.INVALID_MAGIC_CODE, EAuthenticationErrorCodes.EXPIRED_MAGIC_CODE].includes( [
errorhandler.code EAuthenticationErrorCodes.INVALID_EMAIL_MAGIC_SIGN_IN,
) EAuthenticationErrorCodes.INVALID_EMAIL_MAGIC_SIGN_UP,
EAuthenticationErrorCodes.EXPIRED_MAGIC_CODE_SIGN_IN,
EAuthenticationErrorCodes.EXPIRED_MAGIC_CODE_SIGN_UP,
EAuthenticationErrorCodes.EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_IN,
EAuthenticationErrorCodes.EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_UP,
].includes(errorhandler.code)
) )
setAuthStep(EAuthSteps.UNIQUE_CODE); setAuthStep(EAuthSteps.UNIQUE_CODE);
setErrorInfo(errorhandler); setErrorInfo(errorhandler);

View File

@ -53,9 +53,12 @@ export enum EAuthenticationErrorCodes {
INVALID_EMAIL_MAGIC_SIGN_IN = "5080", INVALID_EMAIL_MAGIC_SIGN_IN = "5080",
MAGIC_SIGN_IN_EMAIL_CODE_REQUIRED = "5085", MAGIC_SIGN_IN_EMAIL_CODE_REQUIRED = "5085",
// Both Sign in and Sign up for magic // Both Sign in and Sign up for magic
INVALID_MAGIC_CODE = "5090", INVALID_MAGIC_CODE_SIGN_IN = "5090",
EXPIRED_MAGIC_CODE = "5095", INVALID_MAGIC_CODE_SIGN_UP = "5092",
EMAIL_CODE_ATTEMPT_EXHAUSTED = "5100", EXPIRED_MAGIC_CODE_SIGN_IN = "5095",
EXPIRED_MAGIC_CODE_SIGN_UP = "5097",
EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_IN = "5100",
EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_UP = "5102",
// Oauth // Oauth
GOOGLE_NOT_CONFIGURED = "5105", GOOGLE_NOT_CONFIGURED = "5105",
GITHUB_NOT_CONFIGURED = "5110", GITHUB_NOT_CONFIGURED = "5110",
@ -199,15 +202,27 @@ const errorCodeMessages: {
}, },
// Both Sign in and Sign up // Both Sign in and Sign up
[EAuthenticationErrorCodes.INVALID_MAGIC_CODE]: { [EAuthenticationErrorCodes.INVALID_MAGIC_CODE_SIGN_IN]: {
title: `Authentication failed`, title: `Authentication failed`,
message: () => `Invalid magic code. Please try again.`, message: () => `Invalid magic code. Please try again.`,
}, },
[EAuthenticationErrorCodes.EXPIRED_MAGIC_CODE]: { [EAuthenticationErrorCodes.INVALID_MAGIC_CODE_SIGN_UP]: {
title: `Authentication failed`,
message: () => `Invalid magic code. Please try again.`,
},
[EAuthenticationErrorCodes.EXPIRED_MAGIC_CODE_SIGN_IN]: {
title: `Expired magic code`, title: `Expired magic code`,
message: () => `Expired magic code. Please try again.`, message: () => `Expired magic code. Please try again.`,
}, },
[EAuthenticationErrorCodes.EMAIL_CODE_ATTEMPT_EXHAUSTED]: { [EAuthenticationErrorCodes.EXPIRED_MAGIC_CODE_SIGN_UP]: {
title: `Expired magic code`,
message: () => `Expired magic code. Please try again.`,
},
[EAuthenticationErrorCodes.EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_IN]: {
title: `Expired magic code`,
message: () => `Expired magic code. Please try again.`,
},
[EAuthenticationErrorCodes.EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_UP]: {
title: `Expired magic code`, title: `Expired magic code`,
message: () => `Expired magic code. Please try again.`, message: () => `Expired magic code. Please try again.`,
}, },
@ -334,9 +349,12 @@ export const authErrorHandler = (
EAuthenticationErrorCodes.INVALID_EMAIL_SIGN_IN, EAuthenticationErrorCodes.INVALID_EMAIL_SIGN_IN,
EAuthenticationErrorCodes.INVALID_EMAIL_MAGIC_SIGN_IN, EAuthenticationErrorCodes.INVALID_EMAIL_MAGIC_SIGN_IN,
EAuthenticationErrorCodes.MAGIC_SIGN_IN_EMAIL_CODE_REQUIRED, EAuthenticationErrorCodes.MAGIC_SIGN_IN_EMAIL_CODE_REQUIRED,
EAuthenticationErrorCodes.INVALID_MAGIC_CODE, EAuthenticationErrorCodes.INVALID_MAGIC_CODE_SIGN_IN,
EAuthenticationErrorCodes.EXPIRED_MAGIC_CODE, EAuthenticationErrorCodes.INVALID_MAGIC_CODE_SIGN_UP,
EAuthenticationErrorCodes.EMAIL_CODE_ATTEMPT_EXHAUSTED, EAuthenticationErrorCodes.EXPIRED_MAGIC_CODE_SIGN_IN,
EAuthenticationErrorCodes.EXPIRED_MAGIC_CODE_SIGN_UP,
EAuthenticationErrorCodes.EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_IN,
EAuthenticationErrorCodes.EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_UP,
EAuthenticationErrorCodes.GOOGLE_NOT_CONFIGURED, EAuthenticationErrorCodes.GOOGLE_NOT_CONFIGURED,
EAuthenticationErrorCodes.GITHUB_NOT_CONFIGURED, EAuthenticationErrorCodes.GITHUB_NOT_CONFIGURED,
EAuthenticationErrorCodes.GOOGLE_OAUTH_PROVIDER_ERROR, EAuthenticationErrorCodes.GOOGLE_OAUTH_PROVIDER_ERROR,