Some checks failed
CodeQL / Analyze (javascript) (push) Failing after 16s
CodeQL / Analyze (python) (push) Failing after 3s
i18n sync check / check:sync (push) Failing after 3s
React Doctor / react-doctor (push) Failing after 16s
Branch Build CE / Build-Push Admin Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Merge Admin Manifest (push) Has been cancelled
Branch Build CE / Build-Push Web Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Merge Web Manifest (push) Has been cancelled
Branch Build CE / Build-Push Space Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Merge Proxy Manifest (push) Has been cancelled
Branch Build CE / Merge Space Manifest (push) Has been cancelled
Branch Build CE / Prepare AIO Assets (push) Has been cancelled
Branch Build CE / Build Setup (push) Has been cancelled
Branch Build CE / Build-Push Live Collaboration Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Merge Live Collaboration Manifest (push) Has been cancelled
Branch Build CE / Build-Push API Server Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Merge API Server Manifest (push) Has been cancelled
Branch Build CE / Build-Push Proxy Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Build-Push AIO Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Merge AIO Manifest (push) Has been cancelled
Branch Build CE / Upload Build Assets (push) Has been cancelled
Branch Build CE / Build Release (push) Has been cancelled
101 lines
3.5 KiB
TypeScript
101 lines
3.5 KiB
TypeScript
/**
|
|
* Copyright (c) 2023-present Plane Software, Inc. and contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
* See the LICENSE file for details.
|
|
*/
|
|
|
|
import Link from "next/link";
|
|
// plane packages
|
|
import type { TAdminAuthErrorInfo } from "@plane/constants";
|
|
import { SUPPORT_EMAIL, EAdminAuthErrorCodes } from "@plane/constants";
|
|
|
|
export enum EErrorAlertType {
|
|
BANNER_ALERT = "BANNER_ALERT",
|
|
INLINE_FIRST_NAME = "INLINE_FIRST_NAME",
|
|
INLINE_EMAIL = "INLINE_EMAIL",
|
|
INLINE_PASSWORD = "INLINE_PASSWORD",
|
|
INLINE_EMAIL_CODE = "INLINE_EMAIL_CODE",
|
|
}
|
|
|
|
const errorCodeMessages: {
|
|
[key in EAdminAuthErrorCodes]: { title: string; message: (email?: string) => React.ReactNode };
|
|
} = {
|
|
// admin
|
|
[EAdminAuthErrorCodes.ADMIN_ALREADY_EXIST]: {
|
|
title: `Admin already exists`,
|
|
message: () => `Admin already exists. Please try again.`,
|
|
},
|
|
[EAdminAuthErrorCodes.REQUIRED_ADMIN_EMAIL_PASSWORD_FIRST_NAME]: {
|
|
title: `Email, password and first name required`,
|
|
message: () => `Email, password and first name required. Please try again.`,
|
|
},
|
|
[EAdminAuthErrorCodes.INVALID_ADMIN_EMAIL]: {
|
|
title: `Invalid admin email`,
|
|
message: () => `Invalid admin email. Please try again.`,
|
|
},
|
|
[EAdminAuthErrorCodes.INVALID_ADMIN_PASSWORD]: {
|
|
title: `Invalid admin password`,
|
|
message: () => `Invalid admin password. Please try again.`,
|
|
},
|
|
[EAdminAuthErrorCodes.REQUIRED_ADMIN_EMAIL_PASSWORD]: {
|
|
title: `Email and password required`,
|
|
message: () => `Email and password required. Please try again.`,
|
|
},
|
|
[EAdminAuthErrorCodes.ADMIN_AUTHENTICATION_FAILED]: {
|
|
title: `Authentication failed`,
|
|
message: () => `Authentication failed. Please try again.`,
|
|
},
|
|
[EAdminAuthErrorCodes.ADMIN_USER_ALREADY_EXIST]: {
|
|
title: `Admin user already exists`,
|
|
message: () => (
|
|
<div>
|
|
Admin user already exists.
|
|
<Link className="font-medium underline underline-offset-4 transition-all hover:font-bold" href={`/admin`}>
|
|
Sign In
|
|
</Link>
|
|
now.
|
|
</div>
|
|
),
|
|
},
|
|
[EAdminAuthErrorCodes.ADMIN_USER_DOES_NOT_EXIST]: {
|
|
title: `Admin user does not exist`,
|
|
message: () => (
|
|
<div>
|
|
Admin user does not exist.
|
|
<Link className="font-medium underline underline-offset-4 transition-all hover:font-bold" href={`/admin`}>
|
|
Sign In
|
|
</Link>
|
|
now.
|
|
</div>
|
|
),
|
|
},
|
|
[EAdminAuthErrorCodes.ADMIN_USER_DEACTIVATED]: {
|
|
title: `User account deactivated`,
|
|
message: () => `User account deactivated. Please contact ${SUPPORT_EMAIL ? SUPPORT_EMAIL : "administrator"}.`,
|
|
},
|
|
};
|
|
|
|
export const authErrorHandler = (errorCode: EAdminAuthErrorCodes, email?: string): TAdminAuthErrorInfo | undefined => {
|
|
const bannerAlertErrorCodes = [
|
|
EAdminAuthErrorCodes.ADMIN_ALREADY_EXIST,
|
|
EAdminAuthErrorCodes.REQUIRED_ADMIN_EMAIL_PASSWORD_FIRST_NAME,
|
|
EAdminAuthErrorCodes.INVALID_ADMIN_EMAIL,
|
|
EAdminAuthErrorCodes.INVALID_ADMIN_PASSWORD,
|
|
EAdminAuthErrorCodes.REQUIRED_ADMIN_EMAIL_PASSWORD,
|
|
EAdminAuthErrorCodes.ADMIN_AUTHENTICATION_FAILED,
|
|
EAdminAuthErrorCodes.ADMIN_USER_ALREADY_EXIST,
|
|
EAdminAuthErrorCodes.ADMIN_USER_DOES_NOT_EXIST,
|
|
EAdminAuthErrorCodes.ADMIN_USER_DEACTIVATED,
|
|
];
|
|
|
|
if (bannerAlertErrorCodes.includes(errorCode))
|
|
return {
|
|
type: EErrorAlertType.BANNER_ALERT,
|
|
code: errorCode,
|
|
title: errorCodeMessages[errorCode]?.title || "Error",
|
|
message: errorCodeMessages[errorCode]?.message(email) || "Something went wrong. Please try again.",
|
|
};
|
|
|
|
return undefined;
|
|
};
|