Skip to content

Commit

Permalink
fix: user expired cloud token
Browse files Browse the repository at this point in the history
  • Loading branch information
devcatalin committed Sep 25, 2023
1 parent 0b15fba commit 478ff3a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
4 changes: 2 additions & 2 deletions electron/app/services/cloud/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
7 changes: 2 additions & 5 deletions electron/app/services/cloud/policy.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down
7 changes: 2 additions & 5 deletions electron/app/services/cloud/project.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down
21 changes: 18 additions & 3 deletions electron/app/services/cloud/user.ts
Original file line number Diff line number Diff line change
@@ -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<CloudUser | undefined> => {
export const getUser = async (): Promise<User | undefined> => {
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<CloudUser | undefined> => {
const user = await getUser();
if (!user) {
return undefined;
}
try {
Expand Down

0 comments on commit 478ff3a

Please sign in to comment.