# EmailAddress

The `EmailAddress` object is a model around an email address. Email addresses are one of the identifiers used to provide identification for users.

Email addresses must be **verified** to ensure that they are assigned to their rightful owners. The `EmailAddress` object holds all necessary state around the verification process. The following steps outline the verification process:

1. Initiate the verification process by collecting the user's email address.
2. Prepare the verification process by calling the [prepareVerification()](https://clerk.com/docs/js-frontend/reference/types/email-address.md#prepare-verification) method, which will send an OTP via an email link or code, depending on what parameters are passed to the method and the settings in the Clerk Dashboard.
3. Attempt to complete the verification by calling the [attemptVerification()](https://clerk.com/docs/js-frontend/reference/types/email-address.md#attempt-verification) method, passing the OTP as a parameter.

For implementation examples for adding and verifying email addresses, see the [email link custom flow](https://clerk.com/docs/js-frontend/guides/development/custom-flows/authentication/email-links.md) and [email code custom flow](https://clerk.com/docs/guides/development/custom-flows/account-updates/add-email.md?sdk=js-frontend) guides.

## Properties

| Name                 | Type                          | Description                                                                                                     |
| -------------------- | ----------------------------- | --------------------------------------------------------------------------------------------------------------- |
| id                   | string                        | The unique identifier for the email address.                                                                    |
| emailAddress         | string                        | The value of the email address.                                                                                 |
| matchesSsoConnection | boolean                       | Whether the email address matches an SSO connection.                                                            |
| verification         | VerificationResource          | An object holding information on the verification of the email address.                                         |
| linkedTo             | IdentificationLinkResource[] | An array of objects containing information about any identifications that might be linked to the email address. |

## Methods

### `create()`

Creates a new email address for the current user.

```typescript
function create(): Promise<EmailAddress>
```

### `destroy()`

Deletes the email address.

```typescript
function destroy(): Promise<void>
```

### `toString()`

Returns the value for the email address. Can also be accessed via the `EmailAddress.emailAddress` attribute.

```typescript
function toString(): string
```

### `prepareVerification()`

Initiates the email address verification process. Based on the specified strategy, sends either an OTP or a verification link to the email address. The verification status can be tracked through the `verification` property of the `EmailAddress` object.

```typescript
function prepareVerification(params: PrepareEmailAddressVerificationParams): Promise<EmailAddress>
```

#### `PrepareEmailAddressVerificationParams`

| Name                                                    | Type                                                                                                                                                                                                                                                       | Description                                                                                                                                                                  |
| ------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| email\_link: User will receive an email link via email. | email\_code: User will receive an OTPA one-time password (OTP) is a code that is used to authenticate a user. The OTP is typically sent to a user's email address or phone number and must be entered within a certain time period to be valid. via email. |                                                                                                                                                                              |
| redirectUrl                                             | string | undefined                                                                                                                                                                                                                                        | Required if strategy is set to email\_link. The full URL that the user will be redirected to when they visit the email link. See the custom flow for implementation details. |

### `attemptVerification()`

Attempts to verify an email address using an OTP. The OTP must have been previously sent to the email address via the [EmailAddress.prepareVerification()](https://clerk.com/docs/js-frontend/reference/types/email-address.md#prepare-verification) method with `strategy: 'email_code'`. Returns the updated `EmailAddress` object if verification is successful.

```typescript
function attemptVerification(params: AttemptEmailAddressVerificationParams): Promise<EmailAddress>
```

#### `AttemptEmailAddressVerificationParams`

| Name | Type   | Description                                                                                                                                                                                                                                                                                                                                      |
| ---- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| code | string | The OTPA one-time password (OTP) is a code that is used to authenticate a user. The OTP is typically sent to a user's email address or phone number and must be entered within a certain time period to be valid. that was sent to the user's email address when EmailAddress.prepareVerification() was called with strategy set to email\_code. |

### `createEmailLinkFlow()`

Sets up an email verification with email link flow. Calling `createEmailLinkFlow()` will return two functions.

```typescript
function createEmailLinkFlow(): {
  startEmailLinkFlow: (params: StartEmailLinkFlowParams) => Promise<EmailAddress>
  cancelEmailLinkFlow: () => void
}
```

`createEmailLinkFlow` returns an object with two functions:

| Name                | Type                                                         | Description                                                                                                          |
| ------------------- | ------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------- |
| startEmailLinkFlow  | (params: StartEmailLinkFlowParams) => Promise<EmailAddress> | Function to start the email link flow. It sends the email with the email link and polls for the verification result. |
| cancelEmailLinkFlow | () => void                                                   | Function to stop polling for the verification result, allowing for full control of the flow and cleanup.             |

#### `StartEmailLinkFlowParams`

| Name        | Type   | Description                                                                      |
| ----------- | ------ | -------------------------------------------------------------------------------- |
| redirectUrl | string | The full URL that the user will be redirected to when they visit the email link. |

### `createEnterpriseSSOLinkFlow()`

Sets up an email verification with enterprise SSO link flow. Calling `createEnterpriseSSOLinkFlow()` will return two functions.

```typescript
function createEnterpriseSSOLinkFlow(): {
  startEnterpriseSSOLinkFlow: (params: StartEnterpriseSSOLinkFlowParams) => Promise<EmailAddress>
  cancelEnterpriseSSOLinkFlow: () => void
}
```

`createEnterpriseSSOLinkFlow` returns an object with two functions:

| Name                        | Type                                                                 | Description                                                                                                                            |
| --------------------------- | -------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| startEnterpriseSSOLinkFlow  | (params: StartEnterpriseSSOLinkFlowParams) => Promise<EmailAddress> | Function to start the enterprise SSO link flow. It sends the email with the enterprise SSO link and polls for the verification result. |
| cancelEnterpriseSSOLinkFlow | () => void                                                           | Function to stop polling for the verification result, allowing for full control of the flow and cleanup.                               |

#### `StartEnterpriseSSOLinkFlowParams`

| Name        | Type   | Description                                                                               |
| ----------- | ------ | ----------------------------------------------------------------------------------------- |
| redirectUrl | string | The full URL that the user will be redirected to when they visit the enterprise SSO link. |

---

## Sitemap

[Overview of all docs pages](https://clerk.com/docs/llms.txt)
