การรีเซ็ตรหัสผ่านและการยืนยันอีเมล
เติมเต็มระบบยืนยันตัวตนด้วยอีเมลและรหัสผ่าน โดยให้ผู้ใช้รีเซ็ตรหัสผ่านที่ลืมและยืนยันที่อยู่อีเมลได้ ซึ่งช่วยเพิ่มทั้งความปลอดภัยและความสามารถในการกู้คืนบัญชี
การรีเซ็ตรหัสผ่านและการยืนยันอีเมล เป็นบทเรียน Firebase Auth & Realtime Database Apps ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Firebase Auth & Realtime Database Apps และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Firebase Auth & Realtime Database Apps มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Why Reset and Verification Matter
Email/password sign-in is incomplete without two flows: password reset for forgotten credentials and email verification to prove the user owns the address.
- Reset reduces support tickets and lockouts
- Verification blocks fake or mistyped emails
How Password Reset Works
The flow is entirely email-driven so the user never reveals an old password:
- User requests a reset for their email
- Firebase sends a secure, time-limited link
- User clicks it and chooses a new password
Your app only triggers the email; Firebase hosts the reset page by default.
Triggering a Reset Email
Call sendPasswordResetEmail with the user's address. Firebase handles delivery and the link.
import { getAuth, sendPasswordResetEmail } from 'firebase/auth';
const auth = getAuth();
await sendPasswordResetEmail(auth, 'user@example.com');
console.log('Reset email sent');Handling Reset Errors Gracefully
For security, avoid revealing whether an email exists. Show the same confirmation message whether or not the account is found.
try {
await sendPasswordResetEmail(auth, email);
} catch (e) {
// log internally but do not expose to user
}
showMessage('If that email exists, a reset link was sent.');Sending a Verification Email
After a user signs up, send a verification email with sendEmailVerification on the current user object.
import { getAuth, sendEmailVerification } from 'firebase/auth';
const user = getAuth().currentUser;
if (user) {
await sendEmailVerification(user);
}Checking Verification Status
The user object exposes emailVerified. Use it to gate sensitive features until the address is confirmed.
const user = getAuth().currentUser;
if (user && !user.emailVerified) {
showBanner('Please verify your email to continue.');
}Refreshing the Token After Verification
The emailVerified flag is cached in the ID token. After a user verifies, call reload to refresh their local state.
const user = getAuth().currentUser;
await user.reload();
console.log('Verified now?', user.emailVerified);Customizing Email Templates
In the Firebase console under Authentication > Templates you can customize the sender name, subject, and body of reset and verification emails, and set a custom action URL for branded pages.
Enforcing Verification
You can require a verified email before granting access to certain data using Security Rules. Tokens carry an email_verified claim you can check.
{
"rules": {
"posts": {
".write": "auth != null && auth.token.email_verified == true"
}
}
}Rate Limiting and Abuse
Firebase throttles repeated reset and verification requests to prevent abuse and spam. In your UI, disable the button briefly after sending so users do not trigger the limit accidentally.
Putting It Together
A complete signup typically looks like: create account, send verification email, show a 'check your inbox' screen, and reveal full features once emailVerified becomes true. A 'Forgot password?' link calls the reset flow.
Quick Check
Test your understanding of reset and verification.
Recap
Your email/password auth is now complete and recoverable.
- Use
sendPasswordResetEmailfor forgotten passwords - Avoid revealing whether an email exists
- Verify ownership with
sendEmailVerificationandemailVerified - Call
reloadto refresh status - Customize templates and enforce verification via rules
เรียนรู้ Firebase Auth & Realtime Database Apps ด้วย AI tutor — ฟรี
เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป
- คอร์ส
- 11
- บทเรียน
- 44
คำถามที่พบบ่อย
บทเรียน “การรีเซ็ตรหัสผ่านและการยืนยันอีเมล” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การรีเซ็ตรหัสผ่านและการยืนยันอีเมล” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Firebase Auth & Realtime Database Apps ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Firebase Auth & Realtime Database Apps มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “การรีเซ็ตรหัสผ่านและการยืนยันอีเมล”
เติมเต็มระบบยืนยันตัวตนด้วยอีเมลและรหัสผ่าน โดยให้ผู้ใช้รีเซ็ตรหัสผ่านที่ลืมและยืนยันที่อยู่อีเมลได้ ซึ่งช่วยเพิ่มทั้งความปลอดภัยและความสามารถในการกู้คืนบัญชี คุณปฏิบัติ Firebase Auth & Realtime Database Apps ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Firebase Auth & Realtime Database Apps หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Firebase Auth & Realtime Database Apps บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “การรีเซ็ตรหัสผ่านและการยืนยันอีเมล” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Firebase Auth & Realtime Database Apps นี้ได้ไหม
ได้ บทเรียน Firebase Auth & Realtime Database Apps ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การใช้งานการยืนยันตัวตนด้วยอีเมลและรหัสผ่าน
- การจัดการเซสชันและสถานะผู้ใช้
- การจัดการข้อผิดพลาดในการยืนยันตัวตน
- การรีเซ็ตรหัสผ่านและการยืนยันอีเมล