# Cypress login through magic link error with cy.origin

With Humanless returning the magic link from the email, the usual cause of this error is that the link is on a different origin from the one the test started on. Wrap that visit in `cy.origin(linkOrigin, ...)` and pass the URL in through `args`, because the callback can't see variables from outside. Humanless gives you the URL to visit: a `cy.task` calls `waitForLink`, which returns the sign-in link already extracted from the email, so `new URL(url).origin` tells you which origin to use. If the link lands back on your own app's origin, a plain `cy.visit(url)` is enough. On Cypress versions before 12, `cy.origin` also needs `experimentalSessionAndOrigin` turned on.

```ts magic-link-origin.cy.ts
// Tasks (createInbox, waitForCode, waitForLink): see /answers/how-to-read-emails-in-cypress
cy.task("waitForLink", { id: identityId, since }).then((link) => {
  const url = String(link);
  cy.origin(new URL(url).origin, { args: { url } }, ({ url }) => {
    cy.visit(url);
  });
});
cy.url().should("include", "/dashboard");
```

## Other options

- **Mailpit** to capture the email locally, then the same `cy.origin` pattern.
- **Configure the auth provider to redirect to your app's origin**, so after the provider's verify step the test is back on the original origin.
- **Programmatic login** through your provider's API when the test isn't about the email itself.

> **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/cypress-login-through-magic-link-error-with-cy-origin

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