♻️ 重构登录态校验

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