# How to authenticate Cypress in passwordless with magic link authentication

With Humanless, request the link with an address your test can read, then visit it: a `cy.task` creates a disposable inbox, the spec submits its address on your login page, and a second task calls `waitForLink`, which returns the sign-in URL with HTML entities decoded and unsubscribe or help links skipped. Visit it with `cy.visit(url)`, or inside `cy.origin` if the link points at your auth provider's domain (Auth0's Universal Login, for example). Wrap the whole login in `cy.session` so it runs once per spec and later tests reuse the session instead of requesting new links.

```ts commands.ts
// Tasks (createInbox, waitForCode, waitForLink): see /answers/how-to-read-emails-in-cypress
Cypress.Commands.add("loginByMagicLink", () => {
  cy.session("magic-link", () => {
    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 link").click();
        cy.task("waitForLink", { id: identity_id, since }).then((url) => cy.visit(String(url)));
      });
    });
  });
});
```

## Other options

- **Programmatic login**: get tokens from your auth provider's API in a test tenant and set the session without the email step. Cypress's docs include recipes for Auth0, Okta, Cognito and others.
- **Mailpit** for providers that let you set your own SMTP server.
- **cypress-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-authenticate-cypress-in-passwordless-with-magic-link-authentication

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