နားလည်ထားရမယ့် အချက်
ဤ project သည် ဤ course ထဲက identity နှင့် messaging ကို အဓိကထားသော lesson နှစ်ခုဖြစ်သည့် mobile authentication architecture နှင့် push notification architecture ကို ပေါင်းစပ်ထားသည်။ lesson တစ်ခုချင်းစီက loop တစ်ခုစီကိုသာ ရှင်းပြခဲ့သည် — user တစ်ဦးက သူ့ကိုယ်သူ ဘယ်လို သက်သေပြပြီး session ကို ဘယ်လို ဆက်လက် active ထားလဲ၊ backend က install လုပ်ထားသော app instance အတိအကျတစ်ခုဆီကို polling မလုပ်ဘဲ ဘယ်လို ရောက်စေလဲ။ app အစစ်တစ်ခု တည်ဆောက်ရန်အတွက် ထို loop နှစ်ခုကို ချိတ်ဆက်ဖို့ လိုအပ်သည် — အကြောင်းမှာ backend က user ဘယ်ဦး၏ device ဆီ ပို့ရမည်ကို မသိပါက push notification သည် အသုံးမဝင်တော့သောကြောင့် ဖြစ်ပြီး၊ ထို link သည် authentication နှင့် device registration တို့ တစ်ခုနှင့်တစ်ခု ပြောဆိုမှသာ ရှိလာနိုင်သောကြောင့် ဖြစ်သည်။
- Mobile authentication architecture — login, session token, secure storage, နှင့် နောက်ဆက်တွဲ authenticated call တိုင်း
- Push notification architecture — device-token registration နှင့် backend တစ်ခုက install လုပ်ထားသော app အတိအကျတစ်ခုဆီ ဘယ်လိုရောက်လဲ
ဤ project ၏ စိတ်ကူးယဉ် app သည် user account နှင့် lesson-reminder notification ပါဝင်သော learning platform တစ်ခု ဖြစ်ပြီး၊ ဤ course ရှိရာ site အစစ်နှင့် တမင်တကာ နီးစပ်အောင် ရွေးထားသည်။ learner တစ်ဦးသည် email/password ဖြင့်သော်လည်းကောင်း၊ password သီးခြား စီမံစရာမလိုသော alternative path အဖြစ် Google ကဲ့သို့ OAuth provider မှတစ်ဆင့်သော်လည်းကောင်း login ဝင်နိုင်သည်။
path နှစ်ခုစလုံးသည် mobile authentication architecture ထဲက session token တစ်ခုတည်းဆီသို့ စုစည်းသွားသည်။ ထို token သည် plain preferences ထဲသို့ မဟုတ်ဘဲ device ပေါ်ရှိ secure storage ထဲသို့ ဝင်ပြီး၊ push-notification lesson ၏ device-token registration call အပါအဝင် နောက်ဆက်တွဲ API call တိုင်းသည် ၎င်းကို identity အထောက်အထားအဖြစ် ယူဆောင်သွားသည်။
project တစ်ခုလုံးကို ဆက်စပ်ပေးနေသော design အသေးစိတ်မှာ backend ၏ data model ဖြစ်သည် — device token ကို ၎င်းတစ်ခုတည်းသီးသန့် သိမ်းမည့်အစား၊ authenticated call အောင်မြင်ပြီးမှသာ ဖြည့်စွက်မည့် user id နှင့် linked ဖြစ်သော device token အဖြစ် သိမ်းသည်။
notification ပေးလောက်သော event တစ်ခု ဖြစ်ပေါ်လာသောအခါ — ဤ scenario ၌ lesson အသစ် unlock ဖြစ်လာခြင်း — backend သည် device ကို တိုက်ရိုက် ဆက်သွယ်မည့်အစား ထို user ၏ သိမ်းထားသော device token ကို ရှာဖွေပြီး Apple (သို့) Google ၏ notification service မှတစ်ဆင့် push ကို ပို့သည်။
lookup မတိုင်မီ short-circuit ဖြစ်ရမည်
authenticate မလုပ်ရသေးသော request တစ်ခု (သို့) device token မှတ်ပုံ မတင်ရသေးသော user တစ်ဦးသည် device-token lookup step ကို မရောက်မီ short-circuit ဖြစ်ရမည် — ၎င်းသည် ပါရှိသော code က failure case နှစ်ခုလုံးအတွက် ပြသနေခြင်းပင် ဖြစ်သည်။
MOBILE AUTH + PUSH NOTIFICATION ARCHITECTURE
--------------------------------------------
[Login: password] or [Login: OAuth (Google)]
|
v
[Backend issues session token]
|
v
[Token stored in secure storage on device]
|
v
[Authenticated API calls] + [Device token registration]
|
v
[Backend: user record now linked to device token]
|
v
[Event: new lesson unlocked]
|
v
[Push service: Apple APNs / Google FCM]
|
v
[Learner's device]လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Login — password (သို့) OAuth
learner သည် app ကိုဖွင့်ပြီး password ရိုက်ထည့်ခြင်း (သို့) Google ဖြင့် OAuth redirect ပြီးမြောက်ခြင်း တစ်ခုခုကို ပြုလုပ်သည်။ path နှစ်ခုစလုံးသည် နေရာတစ်ခုတည်းသို့ ရောက်သည် — backend က session token ထုတ်ပေးသည်။
Token ကို secure storage ထဲသို့
app သည် ထို session token ကို plain app preferences ထဲသို့ မဟုတ်ဘဲ secure storage ထဲသို့ ချက်ချင်း ရေးသွင်းသည် — ဒါက app ပြန်ဖွင့်တာနဲ့ ပျက်စီးမသွားစေဘဲ app တခြားများ (သို့) ရိုးရှင်း file-system scan များက ဖတ်လို့မရအောင် ကာကွယ်ပေးသည်။
Device token registration (authenticate ဖြစ်ပြီးမှသာ)
app သည် OS ဆီက device token တောင်းပြီး ကျန် API call အားလုံးနှင့်တူညီသော authorization header ကို အသုံးပြုကာ authenticated endpoint တစ်ခုသို့ ပို့သည်။ session token မရှိပါက (သို့) invalid ဖြစ်ပါက backend က ထို call ကို ချက်ချင်း ပယ်ချသည်။
Backend က device token ကို user နှင့် ချိတ်ဆက်သည်
registration အောင်မြင်ပြီးနောက် backend ၏ user record တွင် account data နှင့် လက်ရှိ device token ကို အတူတကွ ပါဝင်စေသည် — user id အတည်မပြုဘဲ သိမ်းထားသော device token တစ်ခုသည် message ပို့နိုင်သော်လည်း ဘယ်တော့မှ identify မလုပ်နိုင်သော device တစ်ခုသာ ဖြစ်လိမ့်မည်။
Event က push lookup ကို trigger လုပ်သည်
lesson-unlock event ဖြစ်ပေါ်လာသောအခါ backend သည် device ကို တိုက်ရိုက် ထိတွေ့မည်မဟုတ်ပါ။ user ၏ သိမ်းထားသော device token ကို ရှာဖွေပြီး တကယ့် ပို့ဆောင်မှုကို ပြုလုပ်မည့် Apple (သို့) Google ၏ push service ဆီ notification ကို လွှဲပေးသည်။
Failure path ကို ခြေရာခံပါ
authenticate မဖြစ်သေးသော session တစ်ခုနှင့် device registration လုံးဝ မပြီးမြောက်သေးသော user တစ်ဦးကို တမင်တကာ ခြေရာခံကြည့်ပြီး နှစ်ခုစလုံးသည် lookup step မတိုင်မီ ရပ်တန့်ပြီး push service ဆီ လုံးဝ မရောက်ကြောင်း အတည်ပြုပါ။
အတူတူ စမ်းရေးကြည့်မယ်
function simulateAuthAndNotificationFlow(user, event) {
const steps = [];
if (!user.isAuthenticated) {
steps.push("Auth check: FAILED - no valid session token");
steps.push("Aborting before device-token lookup");
return { user: user.name, event, steps, notificationSent: false };
}
steps.push("Auth check: PASSED - session token valid");
if (!user.deviceToken) {
steps.push("Device token lookup: NONE REGISTERED");
steps.push("Aborting before push dispatch");
return { user: user.name, event, steps, notificationSent: false };
}
steps.push(`Device token lookup: FOUND (${user.deviceToken})`);
steps.push(`Event received: "${event}"`);
steps.push(`Push dispatch: sending to ${user.platform} push service`);
steps.push(`Notification delivered to device ${user.deviceToken}`);
return { user: user.name, event, steps, notificationSent: true };
}
const scenarios = [
{
user: {
name: "Aye (authenticated, registered device)",
isAuthenticated: true,
deviceToken: "device-abc123",
platform: "Android (FCM)"
},
event: "New lesson unlocked: How Mobile Apps Work"
},
{
user: {
name: "Unknown visitor (no session)",
isAuthenticated: false,
deviceToken: null,
platform: null
},
event: "New lesson unlocked: How Mobile Apps Work"
}
];
scenarios.forEach(({ user, event }) => {
const result = simulateAuthAndNotificationFlow(user, event);
console.log(`${result.user}`);
result.steps.forEach((s) => console.log(` - ${s}`));
console.log(` Notification sent: ${result.notificationSent}\n`);
});scenario နှစ်ခုကို run လုပ်လျှင် — device register ပြီးသား authenticated user သည် auth check ကို ဖြတ်သန်းပြီး device token "device-abc123" ကို ရှာတွေ့ကာ push dispatch/delivery အောင်မြင်ကြောင်း log ထုတ်ပြီး notificationSent: true နှင့် အဆုံးသတ်သည်။ authenticate မလုပ်ရသေးသော visitor သည် auth check ကို ချက်ချင်း ကျရှုံးကာ abort message တစ်ခု log ထုတ်ပြီး notificationSent: false နှင့် အဆုံးသတ်သည် — device-token lookup ဘယ်တော့မှ run မဖြစ်ပါ။၅ မိနစ် စမ်းကြည့်
simulateAuthAndNotificationFlow ကို scenario တတိယတစ်ခုနှင့် တိုးချဲ့ပါ — session valid ဖြစ်သော်လည်း device token လုံးဝ register မလုပ်ရသေးသော authenticated user တစ်ဦး။ function ကို လက်ဖြင့် ခြေရာခံပြီး ဘယ် log line များ print ထုတ်မလဲ၊ notificationSent သည် true (သို့) false ဖြစ်မလဲ ကြိုတင်ခန့်မှန်းပါ၊ ပြီးမှ run လုပ်ကာ သင့်ခန့်မှန်းချက်ကို စစ်ဆေးပါ။
သတိလေးတစ်ချက်
Session ကို authenticate ဖြစ်ကြောင်း အတည်မပြုမီ device token ကို registration လုပ်ခြင်း — backend က message ပို့နိုင်သော်လည်း ဘယ်တော့မှ identify မလုပ်နိုင်သော device တစ်ခု ကျန်ရစ်စေသည်။
auth flow နှင့် notification flow ကို session token တစ်ခုတည်းကို share သော sequence တစ်ခုတည်းအဖြစ်မဟုတ်ဘဲ ဆက်စပ်မှုမရှိသော diagram နှစ်ခုအဖြစ် သီးခြား design ဆွဲခြင်း။
Firebase Cloud Messaging — Architectural Overview — How Mobile Apps Work