mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
remove code not needed
This commit is contained in:
@@ -1,45 +1,28 @@
|
||||
import { AppwriteException, type Models } from '@appwrite.io/console';
|
||||
import { AppwriteException } from '@appwrite.io/console';
|
||||
|
||||
const EMAIL_VERIFICATION_REQUIRED_ERROR_TYPE = 'user_email_not_verified';
|
||||
const CONSOLE_ACCOUNT_VERIFICATION_REQUIRED_TYPE = 'console_account_verification_required';
|
||||
|
||||
export function isEmailVerificationEnabled(
|
||||
consoleVariables: Models.ConsoleVariables | undefined
|
||||
): boolean {
|
||||
if (!consoleVariables) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return String(consoleVariables._APP_CONSOLE_EMAIL_VERIFICATION) === 'true';
|
||||
}
|
||||
|
||||
export function isEmailVerificationRequiredError(type: string | undefined): boolean {
|
||||
return type === EMAIL_VERIFICATION_REQUIRED_ERROR_TYPE;
|
||||
}
|
||||
|
||||
function matchesVerifyEmailGate(type: string | undefined, message: string | undefined): boolean {
|
||||
if (isEmailVerificationRequiredError(type)) return true;
|
||||
if (type === CONSOLE_ACCOUNT_VERIFICATION_REQUIRED_TYPE) return true;
|
||||
if (message?.includes('Console account verification is required')) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Console APIs may return `user_email_not_verified`, `console_account_verification_required`,
|
||||
* or a message-only error when email verification is enforced for the console account.
|
||||
*/
|
||||
/** True when access is blocked until the console account email is verified. */
|
||||
export function isVerifyEmailRedirectError(error: unknown): boolean {
|
||||
if (error instanceof AppwriteException) {
|
||||
return matchesVerifyEmailGate(error.type, error.message);
|
||||
return (
|
||||
error.type === 'user_email_not_verified' ||
|
||||
error.type === 'console_account_verification_required' ||
|
||||
(error.message?.includes('Console account verification is required') ?? false)
|
||||
);
|
||||
}
|
||||
if (typeof error === 'object' && error !== null && 'message' in error) {
|
||||
|
||||
if (error && typeof error === 'object' && 'message' in error) {
|
||||
const msg = (error as { message: unknown }).message;
|
||||
if (typeof msg !== 'string') return false;
|
||||
const typ =
|
||||
'type' in error && typeof (error as { type: unknown }).type === 'string'
|
||||
? (error as { type: string }).type
|
||||
: undefined;
|
||||
return matchesVerifyEmailGate(typ, msg);
|
||||
return (
|
||||
typ === 'user_email_not_verified' ||
|
||||
typ === 'console_account_verification_required' ||
|
||||
msg.includes('Console account verification is required')
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user