Resetowanie haseł i uwierzytelnianie za pomocą magicznych linków
Dodaj bezhasłowe magiczne linki i bezpieczny proces resetowania hasła do systemu uwierzytelniania Supabase, w tym przekierowanie i wymianę tokenu.
Resetowanie haseł i uwierzytelnianie za pomocą magicznych linków to bezpłatna lekcja Supabase Backend as a Service na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Supabase Backend as a Service, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Supabase Backend as a Service zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
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.
Ucz się Supabase Backend as a Service dzięki korepetycjom AI — za darmo
Pisz i uruchamiaj kod w przeglądarce, otrzymuj natychmiastową pomoc od korepetytora AI dostępnego 24/7 i kontynuuj naukę w sieci lub w aplikacji.
- Kursy
- 11
- Lekcje
- 40
Często zadawane pytania
Czy lekcja „Resetowanie haseł i uwierzytelnianie za pomocą magicznych linków” jest bezpłatna?
Tak — pełny tekst „Resetowanie haseł i uwierzytelnianie za pomocą magicznych linków” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Supabase Backend as a Service, przejdź na CoddyKit PRO. Kurs Supabase Backend as a Service zawiera 4 lekcji w sumie.
Co nauczysz się w „Resetowanie haseł i uwierzytelnianie za pomocą magicznych linków”?
Dodaj bezhasłowe magiczne linki i bezpieczny proces resetowania hasła do systemu uwierzytelniania Supabase, w tym przekierowanie i wymianę tokenu. Ćwiczysz Supabase Backend as a Service z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć Supabase Backend as a Service?
Nie wymagamy żadnego doświadczenia. Supabase Backend as a Service w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.
Ile czasu zajmuje lekcja „Resetowanie haseł i uwierzytelnianie za pomocą magicznych linków”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji Supabase Backend as a Service?
Tak. Każda lekcja Supabase Backend as a Service zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Rejestracja użytkownika za pomocą adresu e-mail i hasła
- Logowanie społecznościowe (dostawcy OAuth)
- Zarządzanie sesjami i profilami użytkowników
- Resetowanie haseł i uwierzytelnianie za pomocą magicznych linków