Magic links and email codes
Passwordless sign-in for existing users: one email carries a sign-in link and a 6-digit code, so people can sign in on the device that has the email or type the code on another.
A magic link signs a user in without a password. Each request sends one email with two ways in: a link that opens your app already signed in, and a 6-digit code for when the email is read on a different device (a laptop) from the one signing in (a phone).
Magic links work for people who already have an account in the project. They never create one: if no account matches the address, nothing is sent, and the request still answers {"status": "sent"} so nobody can learn which addresses are registered. Create accounts first with sign-up or Social sign-in, or add people yourself with Invite user on the console’s Users page, which can email them a magic link straight away.
#Turn on magic links
Enable the provider
In the console, open Users › Sign in / Providers and turn on Magic link. While it is off, sending a link answers
403.Set where links land
Under Users › URL configuration, set your Site URL (for example
https://app.example.com) and add any other address a link may open as a Redirect URL, including app links such asmyapp://auth-callback.Send from your own domain (recommended)
Sovaria sends auth email for you, but production apps should use their own provider so mail comes from your domain and isn't shared with others (Email relays (SMTP)).
#Send the email
Ask for a link with the user's email. redirectTo is where the link opens; it must be your Site URL, a path under it, or one of your Redirect URLs. Anything else is ignored and the link opens your Site URL.
await sovaria.auth.sendMagicLink('ada@example.com', {
redirectTo: 'https://app.example.com/welcome',
})#Sign in with the link
The link opens your redirectTo with ?token=…&type=magiclink added. Hand the URL to the SDK on that page: it exchanges the token for a session and signs the user in.
// On the page the link opens (for example /welcome)
const result = await sovaria.auth.handleEmailLink() // reads window.location
if (result?.type === 'magiclink') {
router.replace('/dashboard') // signed in
}Links that open a mobile app
A link that opens an app (a custom scheme such as myapp://, or a registered universal or app link) could be caught by another app on the same phone. Sovaria therefore binds those links to the app that asked for them with PKCE: the request carries a code_challenge, and only the app holding the matching code_verifier can complete the sign-in. The SDKs do this for you whenever redirectTo is an app link. Calling the HTTP API yourself, send code_challenge (S256) when sending and code_verifier when verifying, or you get 400 PKCE_REQUIRED. See Sign-in for mobile apps.
#Sign in with the code
The same email shows a 6-digit code. Offer a code field next to “Check your email” so people can type it where they are signing in. Spaces are ignored.
await sovaria.auth.verifyEmailCode('ada@example.com', '482913')#What happens when it succeeds
- The user gets a normal session: an access token and a refresh token, kept and refreshed by the SDK like any other sign-in (Sessions and tokens).
- Their email address is marked confirmed, because only the inbox owner could have used the link or code.
- If the user has two-factor authentication, the response is an MFA challenge instead of a session: ask for their code and call
verifyMfa(code)within 5 minutes (Multi-factor authentication). If the project requires MFA and they have none, sign-in is refused with403. - The link and the code are tied together: using either one uses up both.
#Expiry and limits
| Rule | Default | Where to change it |
|---|---|---|
| Link and code expire after | 15 minutes | Fixed |
| Wrong codes allowed before the code stops working | 5 | Users › Rate limits › Email code attempts |
| Links per address per hour | 3 | Users › Rate limits › Magic links per address |
| Requests per IP address per hour | 5 | Users › Rate limits › Magic links per IP |
| Auth emails per project per hour | 500 | Users › Rate limits › Emails sent |
Going over a limit answers 429 with a message you can show. With CAPTCHA on (Users › Attack protection), send the token from your widget with the request; the Dart, Swift and Kotlin SDKs take it as captchaToken.
#Customize the email
The email uses the magic_link template. On plans with custom templates you can change its subject and body under Users › Email, using {{ magic_link_url }}, {{ otp_code }}, {{ project_name }}, {{ email }} and {{ ttl_minutes }} (Auth emails).
#Test it
- Add a test user with Invite user on the Users page, using an inbox you can read, then request a link from your app.
- To see every message your project sends while testing, point custom SMTP at a testing inbox service such as Mailtrap.
- Nothing arrives? Check that the address belongs to a user in this project (each project has its own users), that Magic link is on, and that you are under the hourly limits (Troubleshooting authentication).
#Coming from Firebase or Supabase?
| Platform | What this is called there |
|---|---|
| Firebase | Firebase email link sign-in |
| Supabase | Supabase magic links and OTP |
| Sovaria | Magic links and email codes |
Moving an existing app? Migrate from Supabase or Firebase imports users (with their passwords), data, files and rules.