♻️ 重构登录态校验

This commit is contained in:
BTMuli
2023-12-12 13:49:18 +08:00
parent d5beea5c2d
commit 57e055ebe8

View File

@@ -64,7 +64,11 @@ async function listenOnInit(): Promise<void> {
await tauri.invoke("register_deep_link"); await tauri.invoke("register_deep_link");
await getDeepLink(); await getDeepLink();
await checkAppLoad(); await checkAppLoad();
await checkUserLoad(); try {
await checkUserLoad();
} catch (error) {
console.error(error);
}
await checkUpdate(); await checkUpdate();
}); });
return; return;
@@ -92,17 +96,8 @@ async function checkAppLoad(): Promise<void> {
// 检测 ck,info 数据 // 检测 ck,info 数据
async function checkUserLoad(): Promise<void> { async function checkUserLoad(): Promise<void> {
if (!appStore.isLogin) {
console.info("未登录!");
return;
}
const userStore = useUserStore();
const ckLocal = userStore.cookie;
const ckDB = await TGSqlite.getCookie(); const ckDB = await TGSqlite.getCookie();
if (JSON.stringify(ckLocal) !== JSON.stringify(ckDB)) { if (JSON.stringify(ckDB) === "{}" && appStore.isLogin) {
userStore.cookie = ckDB;
console.info("cookie 数据已更新!");
} else if (JSON.stringify(ckLocal) === "{}") {
await new Promise((resolve) => { await new Promise((resolve) => {
setTimeout(() => { setTimeout(() => {
showSnackbar({ showSnackbar({
@@ -113,6 +108,17 @@ async function checkUserLoad(): Promise<void> {
resolve(true); resolve(true);
}, 3000); }, 3000);
}); });
appStore.isLogin = false;
return;
}
if (JSON.stringify(ckDB) !== "{}" && !appStore.isLogin) {
appStore.isLogin = true;
}
const userStore = useUserStore();
const ckLocal = userStore.cookie;
if (JSON.stringify(ckLocal) !== JSON.stringify(ckDB)) {
userStore.cookie = ckDB;
console.info("cookie 数据已更新!");
} else { } else {
console.info("cookie 数据已加载!"); console.info("cookie 数据已加载!");
} }