Guides / How to test magic-link login end to end

How to test magic-link login end to end

Passwordless sign-in is easy for users and awkward to test: the important part happens in an email. This guide receives the real email, picks out the sign-in link for you and opens it in the test browser.

How BlinkInbox finds the link

Every incoming message is scanned for links. Links whose URL or button text look like sign-in, verify, confirm or reset actions are marked as verification links, and unsubscribe, privacy and social links are ignored. The best match is returned as verificationLink, and the full list is in links.

For an email with only a link and no code, the /otp endpoint returns otp: null and the link filled in, so the same call works for both kinds of email.

response
GET /inboxes/{id}/otp?timeout=30

{
  "otp": null,
  "verificationLink": "https://app.example.com/auth/magic?token=…",
  "from": "login@example.com",
  "subject": "Sign in to Example"
}

Playwright

tests/magic-link.spec.ts
test("magic-link sign-in", async ({ page, request }) => {
  const inbox = await (await request.post(`${API}/inboxes`, { headers, data: { prefix: "magic" } })).json();

  await page.goto("/login");
  await page.getByLabel("Email").fill(inbox.address);
  await page.getByRole("button", { name: "Email me a link" }).click();

  const { verificationLink } = await (await request.get(
    `${API}/inboxes/${inbox.id}/otp?timeout=30`, { headers }
  )).json();

  await page.goto(verificationLink);
  await expect(page.getByText("Signed in")).toBeVisible();
});

Things worth asserting

  • The link points at the right environment (staging links in staging emails, not production).
  • Opening the link twice fails the second time, if your links are meant to be single-use.
  • An expired link shows a helpful error. Wait past the expiry, or shorten it in your test configuration.
  • The email’s sender and subject are what you expect: from and subject are in the same response.

Questions

What if the wrong link is picked?
Every candidate link is in the links field of the full message (GET /inboxes/{id}/messages/{messageId}), each with its anchor text. Choose by text or URL pattern if your email has several call-to-action buttons.
Does it work with tracking redirects?
Yes. verificationLink is the URL as written in the email, including tracking redirects; opening it in the browser follows them as a user would.

Try it

A free Developer account gets you an API key and MCP access with 3 inboxes in any 24 hours.

More guides