Fix auth verification flow and alert ID fallback
This commit is contained in:
Vendored
+18
-11
@@ -30,20 +30,25 @@ export function bootstrapApp() {
|
||||
outlet: document.querySelector('#route-view'),
|
||||
});
|
||||
|
||||
function applyKitchens(kitchens) {
|
||||
store.setKitchens(kitchens);
|
||||
if (!store.activeKitchen && kitchens.length) {
|
||||
store.setActiveKitchen(kitchens[0]);
|
||||
}
|
||||
return kitchens;
|
||||
}
|
||||
|
||||
window.__loncApp = {
|
||||
navigate,
|
||||
async refreshKitchens() {
|
||||
const kitchens = await listKitchens(store);
|
||||
store.setKitchens(kitchens);
|
||||
if (!store.activeKitchen && kitchens.length) {
|
||||
store.setActiveKitchen(kitchens[0]);
|
||||
}
|
||||
return kitchens;
|
||||
return applyKitchens(await listKitchens(store));
|
||||
},
|
||||
async restoreSession() {
|
||||
try {
|
||||
await restoreSession(store);
|
||||
if (store.isConnected) {
|
||||
const result = await restoreSession(store);
|
||||
if (result?.kitchens) {
|
||||
applyKitchens(result.kitchens);
|
||||
} else if (store.isConnected) {
|
||||
await window.__loncApp.refreshKitchens();
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -53,11 +58,13 @@ export function bootstrapApp() {
|
||||
}
|
||||
},
|
||||
async verifyConnection() {
|
||||
await verifyConnection(store);
|
||||
if (store.isConnected) {
|
||||
const result = await verifyConnection(store);
|
||||
if (result?.kitchens) {
|
||||
applyKitchens(result.kitchens);
|
||||
} else if (store.isConnected) {
|
||||
await window.__loncApp.refreshKitchens();
|
||||
}
|
||||
return store.session;
|
||||
return result;
|
||||
},
|
||||
async logout() {
|
||||
await logout(store);
|
||||
|
||||
+9
-1
@@ -18,6 +18,14 @@ const defaultState = {
|
||||
alerts: [],
|
||||
};
|
||||
|
||||
function createAlertId() {
|
||||
if (typeof globalThis !== 'undefined' && globalThis.crypto?.randomUUID) {
|
||||
return globalThis.crypto.randomUUID();
|
||||
}
|
||||
|
||||
return `alert-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
|
||||
}
|
||||
|
||||
export function createAppStore() {
|
||||
const state = {
|
||||
...defaultState,
|
||||
@@ -80,7 +88,7 @@ export function createAppStore() {
|
||||
},
|
||||
addAlert(alert) {
|
||||
const nextAlert = {
|
||||
id: crypto.randomUUID(),
|
||||
id: createAlertId(),
|
||||
type: 'info',
|
||||
timeout: 5000,
|
||||
...alert,
|
||||
|
||||
Reference in New Issue
Block a user