lib/auth/verify-email
Ce contenu n’est pas encore disponible dans votre langue.
Functions
Section titled “Functions”createEmailVerificationRequest()
Section titled “createEmailVerificationRequest()”function createEmailVerificationRequest(userId: string): Promise<{ expiresAt: Date; id: string; token: string; userId: string;}>
Defined in: studiocms/packages/studiocms/src/lib/auth/verify-email.ts:82
Creates an email verification request for a given user.
This function first deletes any existing email verification requests for the user, and then creates a new email verification request using the studioCMS SDK.
Parameters
Section titled “Parameters”userId
Section titled “userId”string
The unique identifier of the user for whom the email verification request is being created.
Returns
Section titled “Returns”Promise
<{
expiresAt
: Date
;
id
: string
;
token
: string
;
userId
: string
;
}>
A promise that resolves to the result of the email verification request creation.
deleteEmailVerificationRequest()
Section titled “deleteEmailVerificationRequest()”function deleteEmailVerificationRequest(id: string): Promise<void>
Defined in: studiocms/packages/studiocms/src/lib/auth/verify-email.ts:69
Deletes an email verification request by its ID.
Parameters
Section titled “Parameters”string
The unique identifier of the email verification request to be deleted.
Returns
Section titled “Returns”Promise
<void
>
A promise that resolves when the email verification request is successfully deleted.
getEmailVerificationRequest()
Section titled “getEmailVerificationRequest()”function getEmailVerificationRequest(id: string): Promise< | null | { expiresAt: Date; id: string; token: string; userId: string;}>
Defined in: studiocms/packages/studiocms/src/lib/auth/verify-email.ts:57
Retrieves an email verification request by its ID.
Parameters
Section titled “Parameters”string
The unique identifier of the email verification request.
Returns
Section titled “Returns”Promise
<
| null
| {
expiresAt
: Date
;
id
: string
;
token
: string
;
userId
: string
;
}>
A promise that resolves to the email verification request.
isEmailVerificationEnabled()
Section titled “isEmailVerificationEnabled()”function isEmailVerificationEnabled(): Promise<boolean>
Defined in: studiocms/packages/studiocms/src/lib/auth/verify-email.ts:44
Checks if email verification is enabled in the StudioCMS configuration.
This function retrieves the notification settings from the database and
returns the value of the emailVerification
property. If the settings
are not available, it defaults to false
.
Returns
Section titled “Returns”Promise
<boolean
>
A promise that resolves to true
if email
verification is enabled, otherwise false
.
isEmailVerified()
Section titled “isEmailVerified()”function isEmailVerified(user: | undefined | CombinedUserData| UserSessionData): Promise<boolean>
Defined in: studiocms/packages/studiocms/src/lib/auth/verify-email.ts:169
Checks if the user’s email is verified based on various conditions.
Parameters
Section titled “Parameters”The user data which includes email verification status and permissions.
undefined
| CombinedUserData
| UserSessionData
Returns
Section titled “Returns”Promise
<boolean
>
A promise that resolves to a boolean indicating whether the user’s email is verified.
The function performs the following checks:
- If the user is undefined, returns false.
- If the mailer is not enabled, returns true.
- If email verification is not required in settings, returns true.
- If OAuth bypass verification is enabled and the user has OAuth data, returns true.
- Based on the user’s rank:
- ‘owner’: Always returns true.
- ‘admin’: Returns the user’s email verification status if admin verification is required, otherwise returns true.
- ‘editor’: Returns the user’s email verification status if editor verification is required, otherwise returns true.
- Default: Returns the user’s email verification status.
sendVerificationEmail()
Section titled “sendVerificationEmail()”function sendVerificationEmail(userId: string, isOAuth: boolean): Promise< | undefined| MailerResponse>
Defined in: studiocms/packages/studiocms/src/lib/auth/verify-email.ts:107
Sends a verification email to the user with the given userId.
Parameters
Section titled “Parameters”userId
Section titled “userId”string
The ID of the user to send the verification email to.
isOAuth
Section titled “isOAuth”boolean
= false
Optional. Indicates if the user is authenticated via OAuth. Defaults to false.
Returns
Section titled “Returns”Promise
<
| undefined
| MailerResponse
>
A promise that resolves to the response of the mail sending operation.
Throws
Section titled “Throws”Will throw an error if the user is not found, if the verification token creation fails, or if the user does not have an email.