إعادة تعيين كلمة المرور والمصادقة عبر الروابط السحرية
أضف الروابط السحرية دون كلمة مرور وتدفقًا آمنًا لإعادة تعيين كلمة المرور إلى مصادقة Supabase، بما في ذلك خطوات إعادة التوجيه وتبادل الرمز المميز.
إعادة تعيين كلمة المرور والمصادقة عبر الروابط السحرية درس مجاني في Supabase Backend as a Service على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Supabase Backend as a Service، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Supabase Backend as a Service 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
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.
الأسئلة الشائعة
هل درس «إعادة تعيين كلمة المرور والمصادقة عبر الروابط السحرية» مجاني؟
نعم — نص درس «إعادة تعيين كلمة المرور والمصادقة عبر الروابط السحرية» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Supabase Backend as a Service، انتقل إلى CoddyKit PRO. تتضمن دورة Supabase Backend as a Service 4 دروس في المجموع.
ماذا ستتعلم في «إعادة تعيين كلمة المرور والمصادقة عبر الروابط السحرية»؟
أضف الروابط السحرية دون كلمة مرور وتدفقًا آمنًا لإعادة تعيين كلمة المرور إلى مصادقة Supabase، بما في ذلك خطوات إعادة التوجيه وتبادل الرمز المميز. تتمرن على Supabase Backend as a Service مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Supabase Backend as a Service؟
لا تُشترط خبرة سابقة. Supabase Backend as a Service على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «إعادة تعيين كلمة المرور والمصادقة عبر الروابط السحرية»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Supabase Backend as a Service هذا؟
نعم. كل درس في Supabase Backend as a Service يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- تسجيل المستخدمين بالبريد الإلكتروني وكلمة المرور
- تسجيل الدخول الاجتماعي (موفرو OAuth)
- إدارة جلسات المستخدمين وملفاتهم الشخصية
- إعادة تعيين كلمة المرور والمصادقة عبر الروابط السحرية