Password Reset and Magic Link Authentication
Add passwordless magic links and a secure password reset flow to your Supabase auth, including the redirect and token exchange steps.
Password Reset and Magic Link Authentication is a free Supabase Backend as a Service lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Supabase Backend as a Service learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Beyond Passwords
Supabase supports passwordless sign-in via magic links and a built-in password reset flow. Both rely on emailing a secure link to the user.
How Magic Links Work
The user enters an email, Supabase emails a one-time link, and clicking it signs them in, no password needed.
- Link contains a single-use token
- Token is exchanged for a session
Sending a Magic Link
Call signInWithOtp with the email and a redirect URL.
const { error } = await supabase.auth.signInWithOtp({
email: 'user@example.com',
options: { emailRedirectTo: 'https://app.example.com/welcome' }
});Configuring Redirect URLs
In the dashboard under Authentication > URL Configuration, allow-list your redirect URLs. Links to non-listed URLs are rejected for security.
Completing the Sign-In
When the user returns, Supabase detects the token in the URL and establishes the session automatically with detectSessionInUrl enabled.
const { data } = await supabase.auth.getSession();
console.log(data.session ? 'Signed in' : 'No session');Starting a Password Reset
Trigger a reset email with resetPasswordForEmail. The link sends the user to a page where they set a new password.
await supabase.auth.resetPasswordForEmail(
'user@example.com',
{ redirectTo: 'https://app.example.com/update-password' }
);Setting the New Password
On the redirect page, the user is in a temporary recovery session. Update the password with updateUser.
const { error } = await supabase.auth.updateUser({
password: 'a-strong-new-password'
});Validating Password Strength
Enforce a minimum standard before submitting to reduce weak credentials.
function strong(pw) {
return pw.length >= 8 && /[0-9]/.test(pw) && /[A-Za-z]/.test(pw);
}
console.log(strong('abc12345'));Token Expiry
Magic links and reset tokens are short-lived and single use. Expired links must trigger a fresh request, so always handle the expiry error gracefully.
Customizing Email Templates
Under Authentication > Email Templates you can brand the magic link and recovery emails so they match your product.
Putting It Together
Magic links remove password friction, and the reset flow gives users a safe recovery path. Both depend on allow-listed redirects and short-lived tokens.
Quick Check
Test your understanding of magic links and resets.
Recap
You added magic link sign-in with signInWithOtp, built a password reset flow with resetPasswordForEmail and updateUser, and learned why allow-listed redirects and short-lived tokens keep it secure.
Frequently asked questions
Is the “Password Reset and Magic Link Authentication” lesson free?
Yes — the full text of “Password Reset and Magic Link Authentication” is free to read here on the web, and the Supabase Backend as a Service course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Supabase Backend as a Service course, upgrade to CoddyKit PRO.
What will I learn in “Password Reset and Magic Link Authentication”?
Add passwordless magic links and a secure password reset flow to your Supabase auth, including the redirect and token exchange steps. You practise Supabase Backend as a Service with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Supabase Backend as a Service?
No prior experience is required. Supabase Backend as a Service on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Password Reset and Magic Link Authentication” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Supabase Backend as a Service lesson?
Yes. Every Supabase Backend as a Service lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- User Registration with Email/Password
- Social Logins (OAuth Providers)
- Managing User Sessions & Profiles
- Password Reset and Magic Link Authentication