# How to write Cypress E2E tests for Supabase's magic link login authentication

Against a hosted Supabase project, Humanless can receive the real magic-link email: create a disposable inbox in a `cy.task`, call `signInWithOtp` through your login form with that address, then `waitForLink` returns the confirmation URL and you `cy.visit` it. The link goes to your project's `/auth/v1/verify` endpoint and redirects back to your site URL, so check that the redirect URL is allowed in your Supabase auth settings. With the PKCE flow, visit the link in the same browser that requested it. Against the local Supabase stack, read the mail from its built-in mail catcher instead of hardcoding a token URL.

```ts supabase-magic-link.cy.ts
// Tasks (createInbox, waitForCode, waitForLink): see /answers/how-to-read-emails-in-cypress
cy.task("createInbox").then(({ identity_id, email }: any) => {
  cy.visit("/login");
  cy.get("input[type=email]").type(email);
  cy.then(() => {
    const since = Date.now();
    cy.contains("button", "Send magic link").click();
    cy.task("waitForLink", { id: identity_id, since }).then((url) => cy.visit(String(url)));
  });
  cy.contains("Signed in as").should("be.visible");
});
```

## Other options

- **The local stack's mail catcher** (port 54324 by default), queried with `cy.request` for the newest message to the address.
- **`supabase.auth.admin.generateLink({ type: "magiclink", email })`** in a `cy.task` with the service role key: returns a link without sending email.
- **Hosted inboxes** such as Mailosaur or MailSlurp.

> **Use policy:** Only for apps you own or are authorized to test. See the [Terms](/terms).

More: [How to test magic link login end to end](/guides/magic-link-testing) · [All answers](/answers/)

Last updated 2026-12-04

Canonical: https://usehumanless.com/answers/how-to-write-cypress-e2e-tests-for-supabase-s-magic-link-login-authentication

---
More: https://usehumanless.com/llms.txt
