Dùng package firebase_auth: await FirebaseAuth.instance.signInWithEmailAndPassword(email: email, password: password).
Lắng nghe trạng thái auth bằng authStateChanges() stream—đây là cách đúng để biết user đã đăng nhập chưa.
Lưu ý phổ biến:
- không lắng nghe
authStateChanges()mà kiểm tracurrentUserngay lập tức—có thể null khi app mới mở; - quên bật Email/Password provider trong Firebase Console;
- quên thêm entitlement trên iOS;
- không wrap trong try/catch dẫn đến crash khi mất mạng
Lưu ý: SHA-1 chỉ cần thiết cho Google Sign-In và OAuth provider, KHÔNG cần cho email/password auth.
Luôn test cả trường hợp offline.
Use firebase_auth: await FirebaseAuth.instance.signInWithEmailAndPassword(email: email, password: password).
Listen to auth state via authStateChanges() stream — the correct way to know if a user is signed in.
Common pitfalls:
- checking
currentUserimmediately on startup (may be null); - forgetting to enable the Email/Password sign-in provider in Firebase Console;
- missing iOS entitlements;
- not wrapping auth calls in try/catch for network errors
Note: SHA-1 is only required for Google Sign-In and OAuth providers — not for email/password auth.