Thuta Learning
Firebase Tutorial
IntermediateDevOps & Toolsအလယ်အလတ်

Email/Password ဖြင့် Login ဝင်ခြင်း

Firebase Tutorialသင်ခန်းစာ 8

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 လုပ်စရာမလိုပါ။

နောက်ဆုံးပြင်ဆင်ရက်

Progress ကို ဤ browser (ဤစက်) တွင်သာ သိမ်းထားပါသည်။ အခြားစက်များနှင့် sync မလုပ်ပါ။

ဤသင်ခန်းစာတွင် အမှားတွေ့ပါက အကြောင်းကြားရန်သင့် email app ကို ဤသင်ခန်းစာလိပ်စာ ဖြည့်ပြီးသားဖြင့် ဖွင့်ပေးပါမည် — သင်ကိုယ်တိုင် ပို့မှသာ ပို့မည်ဖြစ်သည်။

Email/Password ဖြင့် Login ဝင်ခြင်း | Thuta Learning