From 7c08c39af6df620638b6556e23dd0d4078d2c061 Mon Sep 17 00:00:00 2001 From: neil Date: Tue, 17 Jan 2023 20:28:27 +0800 Subject: [PATCH 1/2] fix register device request --- modules/gui/src/libs/stores/auth.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/modules/gui/src/libs/stores/auth.ts b/modules/gui/src/libs/stores/auth.ts index 39273b4..cc963ac 100644 --- a/modules/gui/src/libs/stores/auth.ts +++ b/modules/gui/src/libs/stores/auth.ts @@ -15,11 +15,15 @@ export let session: Session | null = null; export const getSession = async (): Promise => { if (session && session?.user) return session; const sessionFilePath = await join(basePath, 'tmp.dat'); - const encryptedData = await readTextFile(sessionFilePath, { - dir: BaseDirectory.Home - }); - session = JSON.parse(encryptedData || '{}') as Session; - return session; + try { + const encryptedData = await readTextFile(sessionFilePath, { + dir: BaseDirectory.Home + }); + session = JSON.parse(encryptedData || '{}') as Session; + return session; + } catch (error) { + return null; + } }; export default function initAuthStore() { @@ -101,11 +105,10 @@ const getLocalSessionData = async (): Promise => { let data: Session; try { const session = await getSession(); - if (session) { - data = session; - } + if (!session) throw new Error('no session'); + data = session; } catch (error) { - console.error(error); + console.error('register device:',error); const deviceId = await registerDevice(); data = { device_id: deviceId From a0292fa7603e91f8e1b5219003b3feff49e73889 Mon Sep 17 00:00:00 2001 From: neil Date: Tue, 17 Jan 2023 20:29:06 +0800 Subject: [PATCH 2/2] lint --- modules/gui/src/libs/stores/auth.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gui/src/libs/stores/auth.ts b/modules/gui/src/libs/stores/auth.ts index cc963ac..e3c65a7 100644 --- a/modules/gui/src/libs/stores/auth.ts +++ b/modules/gui/src/libs/stores/auth.ts @@ -108,7 +108,7 @@ const getLocalSessionData = async (): Promise => { if (!session) throw new Error('no session'); data = session; } catch (error) { - console.error('register device:',error); + console.error('register device:', error); const deviceId = await registerDevice(); data = { device_id: deviceId