Email/Password ဖြင့် Login ဝင်ခြင်း
Account ရှိပြီးသား user ကို Firebase Auth နဲ့ login ဝင်စေဖို့ signInWithEmailAndPassword ကိုသုံးပါတယ်။
Code Example
javascript
import { getAuth, signInWithEmailAndPassword } from 'firebase/auth';
const auth = getAuth();
async function login(email, password) {
try {
const userCredential = await signInWithEmailAndPassword(auth, email, password);
console.log('Logged in:', userCredential.user.email);
} catch (error) {
console.log('Login failed:', error.code);
}
}
login('student@example.com', 'StrongPass123');သတိထားရမယ့်အချက်
Login အောင်မြင်တာနဲ့ Firebase က session ကိုထိန်းထားပေးပါတယ်။ Page refresh ဖြစ်သွားရင်တောင် login state ကိုပြန်သိနိုင်ဖို့ onAuthStateChanged ကိုသုံးရပါမယ်။
Expected outputLogged in: student@example.com
Security note
Password ကို localStorage ထဲမသိမ်းပါနဲ့။ Firebase Auth က session management ကိုကိုင်ပေးတာကြောင့် ကိုယ်တိုင် password cache လုပ်စရာမလိုပါ။