> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bbrands.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Magic link

> The sign-in link for logins without a password and the activation link for invited customers: who gets it, how long it lasts and how the app and the web consume it.

There are two magic links. The **sign-in magic link** is new in 2026.11.3: any login without a
password gets it, on MaihueGO and on the web (ADR 0134). The **onboarding magic link** is its older
sibling: it activates the account of a customer invited from the portal (ADR 0095). Both are consumed
with a `POST` from the client, never with a plain `GET` from the e-mail.

> [!NOTE]
>
> **Status.** The sign-in magic link ships in PR #1960 (merged into develop on 2026-11-05) with 2026.11.3, with
> no flag. The exit check is manual test MT-06 on iOS and Android.

## Who gets the sign-in magic link

Only a login with **an account and no password**: typically someone who registered with Google, Apple
or Microsoft (ADR 0132), a migrated account or a contract signer. It can be requested in two ways:

* The «Enviarme un enlace» button on the methods step, after the e-mail.
* «Olvidé mi contraseña» when the login has no password: the magic link arrives instead of the
  recovery e-mail, with the same on-screen answer.

> [card] 1 hour
>
> The link expires after one hour. In Supabase, `MAILER_OTP_EXP` = **3600** seconds in all three
> environments.

> [card] Single use
>
> A link already used answers `410 link-expired`.

> [card] Resend after 60 s
>
> The «Revisa tu correo» screen unlocks resend after 60 seconds.

## Step by step

> [tab] MaihueGO (iOS and Android)
>
> **1. E-mail and methods**
>
> The person types their e-mail. `verify-email` says it has an account and no password, and the
> app shows «Este correo no tiene contraseña», the buttons of the enabled providers and
> «Enviarme un enlace». With no provider, only the link is offered.
>
> **2. Request the link**
>
> The app calls `POST /api/v3/auth/magic-link/request` with `origin: "app"` and opens «Revisa tu
> correo».
>
> **3. Open the e-mail**
>
> The link is a universal link on the portal host
> (`https://portal.maihuego.com/redirect?...` in production). With the app installed, the system
> opens MaihueGO directly.
>
> **4. Consume and enter**
>
> The app sends the `token_hash` to `POST /api/v3/auth/magic-link/login`, stores the session and
> opens Home.

> [tab] Web (horizon-authenticate)
>
> **1. E-mail and methods**
>
> Same e-mail step on `auth.bbrands.io`. The server action forwards the person's real IP with
> `x-auth-client-ip` and `x-auth-bff-token`.
>
> **2. Request the link**
>
> `POST /api/v3/auth/magic-link/request` with `origin: "web"` and the `next` of the app that asked
> for the sign-in.
>
> **3. Open the e-mail**
>
> The link points to `https://auth.bbrands.io/<locale>/auth/magic-link?token_hash=...&type=sign-in&next=...`.
> If `next` is not on the redirect allowlist, it is ignored and the default landing page is used.
>
> **4. Consume, 2FA and next**
>
> The page sends the `POST`, removes the token from the address bar, goes through the 2FA gate and
> redirects to `next`.

> [!WARNING]
>
> The magic link **never bypasses 2FA**. Today the gate is inert: the `authenticate-two-factor-ui` flag is off in every
> environment and there is no second-factor backend. See
> [Sessions and SSO](https://docs.bbrands.io/maihuego/authentication/session.md).

An expired or used link leads to a screen that offers to ask for a new one from the e-mail step.

## Endpoints

| Method and path | Contract |
| - | - |
| `POST /api/v3/auth/magic-link/request` | Body `{ email, origin: "app" \| "web", next?, locale? }` (`next` up to 2048 characters). **Always** answers `200 { sent: true }`, whether or not the account exists. Generates the link with `admin.generateLink({ type: "magiclink" })`. |
| `POST /api/v3/auth/magic-link/login` | Body `{ token_hash, ref? }`; sign-in links carry no `ref`. Answers the password-login payload plus `jwt`, `access_token` and `refresh_token`. Accepts only `Content-Type: application/json`. |
| `POST /api/v3/auth/recovery-account` | When the login has no password, sends the sign-in magic link instead of the recovery e-mail. Same answer and same message. |

| `magic-link/login` response | When |
| - | - |
| `410 link-expired` | Only when GoTrue rejects the token (400, 401, 403, 404, 410 or `otp_expired`) |
| `503 magic-link-unavailable` | Supabase does not respond |
| `429` | Consume limit exceeded |

## Limits

| Bucket | Limit | Dimensions | If the limiter is down | Over budget |
| - | - | - | - | - |
| `magic-link-request` | 5 per hour | e-mail and IP | closed | silent: same `{ sent: true }` answer |
| `magic-link` (consume) | 10 per 10 min | IP | closed | `429` |
| `onboarding-magic-link-resend` | 1 per hour | user | local | — |

`magic-link-request` is always enforced, even when the `authenticate-rate-limit-mode` flag is `off`.

## Template and event

The e-mail is the notification event `auth.sign-in.magic-link-requested` (domain `auth`, gateway
`horizon-auth`, in the person's language, `es` and `en` templates at minimum). It is in the security
category: it cannot be opted out of and ignores quiet hours. The template is inserted by
`notification:template-sync` or on first send. The onboarding link keeps its event
`auth.magic-link.requested`.

## Apple hidden e-mail

If the person chose «Hide My Email», their login is an `@privaterelay.appleid.com` address
(`is_private_email = true`). Apple only forwards mail from domains registered in **Sign in with Apple
for Email Communication**: if the sender domain or the Resend return-path is missing, the magic link
bounces and that person cannot sign in without a password. See
[Rollout](https://docs.bbrands.io/maihuego/authentication/setup.md).

> [!NOTE]
>
> A mail scanner that runs JavaScript can consume a link before the person does. ADR 0134 accepts this
> risk: asking for another link is enough.

## Onboarding magic link (invited customers)

This is the link in customer-portal invitations.

1. E-mail «Activa tu cuenta Maihue» with the «Activar mi cuenta» button and the 24-hour notice.
2. The button opens `/es/onboarding/activate?ref=...&token_hash=...` on the portal. The page sends a
   single `POST`, removes `token_hash` from the URL, the portal sets its cookie and the person lands on
   `/es/onboarding` with no extra click.
3. Lifetime: **24 hours**. An expired link (`410`) offers «Reenviar» (only with a `ref`) and «Salir»;
   `429` and `503` show a retry message.

| Method and path | Contract |
| - | - |
| `POST /api/v3/auth/magic-link/resend` | Body `{ ref }`. Always answers `202`: an invalid `ref` is indistinguishable from a sent one. Budget of 1 resend per hour per user. |
| `POST /api/v3/auth/magic-link/validate` | Exchanges the digital-contracting portal link for a Supabase session and the contract context. With an expired OTP it answers `200` with data to recover the link. |

> [!NOTE]
>
> **Pending.** T-107 (onboarding link login and resend) is still in progress, and T-137 will retire the
> horizon-authenticate onboarding magic-link screen once the 24-hour invitations issued before portal
> activation expire.

## See also

* [E-mail sign-in](https://docs.bbrands.io/maihuego/authentication/sign-in.md)
* [Password](https://docs.bbrands.io/maihuego/authentication/password.md)
* [Apple](https://docs.bbrands.io/maihuego/authentication/apple.md)
* [Security and limits](https://docs.bbrands.io/maihuego/authentication/security.md)
* [Rollout](https://docs.bbrands.io/maihuego/authentication/setup.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.