# Test a Supabase email address change with two real inboxes

Follow the two Supabase Secure email change confirmations separately. Check the old address after the first click and sign in with the new address after the second.

Changing the email address in an account settings form takes one click. With Supabase's **Secure email change** enabled, completing the change takes two more: one in the current inbox and one in the proposed inbox. A browser test that stops when the form says the request was sent cannot tell you which address the user can sign in with.

Use two MailSlurp inboxes so Playwright can read each delivery independently. We'll confirm the current address first, reload the account to inspect the pending change, then confirm the replacement address. A fresh password sign-in will tell us whether the new address opens the original account.

## Set up the account and its two mailboxes

[Open the runnable account security example](https://github.com/mailslurp/examples/tree/master/supabase-account-security). In a dedicated Supabase project, enable email/password signup, email confirmation and **Secure email change**. Use a custom SMTP sender that can deliver to your test addresses, keep the standard confirmation-link templates, and allow `http://localhost:3000/` as a redirect. If Secure email change is disabled, Supabase sends the confirmation only to the proposed address. [Supabase email changes](https://supabase.com/docs/reference/javascript/auth-updateuser)

From the example directory, use Node.js 22.13 or newer and install Chromium:

```sh
npm ci
npx playwright install chromium
cp .env.example .env.local
```

Set `VITE_SUPABASE_URL` and `VITE_SUPABASE_PUBLISHABLE_KEY` for the local app. Supply `MAILSLURP_API_KEY` to the Node runner. Run `npm test -- --grep 'secure email change'`. The test signs up a new account with the first inbox, follows its signup confirmation, and saves the user ID. It reserves the second inbox for the proposed address.

## How can I verify my email address effectively?

For an address change, open the confirmation sent to each address and read back the account between clicks. In the example, the signed-in app starts the change with the replacement email and its local callback:

```js
const { error } = await auth.updateUser(
  { email: replacementAddress },
  { emailRedirectTo: location.origin + '/' }
);
if (error) throw error;
```

The runner records when it submits the change, then waits for a new message in each inbox. From each message it selects the verification URL with the project's origin, the `/auth/v1/verify` path, `type=email_change` and the expected callback. The two URLs must be distinct. These checks keep the earlier signup email from satisfying either wait.



### Read both halves of an email change

Give Playwright a separate inbox for each address and read the confirmation that Supabase delivered to each one.

[Create a free MailSlurp account](https://app.mailslurp.com/sign-up/?onboardingRequest=testing)



### Stop after the first confirmation

Open the current inbox's link in a separate browser context. Reload the account settings page in the original browser, where the app calls `auth.getUser()`. After that first click, `user.email` still matched the current inbox, and `user.new_email` indicated a pending change.



![Supabase account settings after the first confirmation show an email change awaiting confirmation](/_astro/one-confirmation.CrFMvsD7_1hYugF.webp)

Only the current mailbox has confirmed. The address is masked in the screenshot; the test compares it with the original inbox.



## Sign in with the replacement address

Now open the link delivered to the second inbox. Start a browser context with no saved session and sign in using the replacement email and the original password. The account page reads its identity from Supabase. Compare both fields:

```js
await expect(tab.locator('#address')).toHaveText(replacement.emailAddress);
await expect(tab.locator('#address')).toHaveAttribute('data-user-id', id);
await expect(tab.locator('#pending')).toHaveText('No pending change');
```



![Account settings after both confirmation links show no pending email change](/_astro/both-confirmations.RTovz4pr_XLXoT.webp)

The replacement address signed in from a fresh browser and opened the same Supabase user ID.



If only one email arrives, first check whether the change request succeeded and whether Secure email change is enabled. When Supabase returns **Error sending email change email**, open the project's Auth logs and inspect the SMTP response. A temporary `421` occurred during this example. Wait for the sender to accept mail again and start a fresh run with a new pair of inboxes. Increasing Playwright's inbox timeout alone cannot deliver a message the sender rejected.
