diff --git a/electron/app/services/cloud/ipc.ts b/electron/app/services/cloud/ipc.ts index f8d87b3fb..8152a5b01 100644 --- a/electron/app/services/cloud/ipc.ts +++ b/electron/app/services/cloud/ipc.ts @@ -2,10 +2,10 @@ import {handleIpc} from '../../utils/ipc'; import {cloudLogin, cloudLogout} from './login'; import {getPolicy} from './policy'; import {getProjectInfo} from './project'; -import {getUser} from './user'; +import {getSerializedUser} from './user'; handleIpc('cloud:login', cloudLogin); handleIpc('cloud:logout', cloudLogout); -handleIpc('cloud:getUser', getUser); +handleIpc('cloud:getUser', getSerializedUser); handleIpc('cloud:getPolicy', getPolicy); handleIpc('cloud:getProjectInfo', getProjectInfo); diff --git a/electron/app/services/cloud/policy.ts b/electron/app/services/cloud/policy.ts index 783b92550..c52744605 100644 --- a/electron/app/services/cloud/policy.ts +++ b/electron/app/services/cloud/policy.ts @@ -1,14 +1,11 @@ import log from 'loglevel'; -import {getAuthenticator} from './authenticator'; import {getSynchronizer} from './synchronizer'; +import {getUser} from './user'; export const getPolicy = async (repoPath: string) => { - const authenticator = await getAuthenticator(); const synchronizer = await getSynchronizer(); - - const user = await authenticator?.getUser(); - + const user = await getUser(); if (!user?.token || !synchronizer) { return null; } diff --git a/electron/app/services/cloud/project.ts b/electron/app/services/cloud/project.ts index 938da6430..95507c7b7 100644 --- a/electron/app/services/cloud/project.ts +++ b/electron/app/services/cloud/project.ts @@ -1,12 +1,9 @@ -import {getAuthenticator} from './authenticator'; import {getSynchronizer} from './synchronizer'; +import {getUser} from './user'; export const getProjectInfo = async (repoPath: string) => { - const authenticator = await getAuthenticator(); const synchronizer = await getSynchronizer(); - - const user = await authenticator?.getUser(); - + const user = await getUser(); if (!user?.token || !synchronizer) { return null; } diff --git a/electron/app/services/cloud/user.ts b/electron/app/services/cloud/user.ts index 97e260a1c..528118b29 100644 --- a/electron/app/services/cloud/user.ts +++ b/electron/app/services/cloud/user.ts @@ -1,15 +1,30 @@ +import log from 'loglevel'; + import {User} from '@monokle/synchronizer'; import {CloudUser} from '@shared/models/cloud'; import {getAuthenticator} from './authenticator'; -export const getUser = async (): Promise => { +export const getUser = async (): Promise => { const authenticator = await getAuthenticator(); if (!authenticator) { return undefined; } - const user = await authenticator.getUser(); - if (!user.isAuthenticated) { + try { + const user = await authenticator.getUser(); + if (!user.isAuthenticated) { + return undefined; + } + return user; + } catch (e: any) { + log.warn(e.message); + return undefined; + } +}; + +export const getSerializedUser = async (): Promise => { + const user = await getUser(); + if (!user) { return undefined; } try {