diff --git a/src/store/user.store.ts b/src/store/user.store.ts index 16b4002a..348066a0 100644 --- a/src/store/user.store.ts +++ b/src/store/user.store.ts @@ -11,8 +11,9 @@ import { updateUserOrganization, } from 'services/user.service'; import { IUserInfo } from 'models/user/IUserInfo'; -import { ROLE_ADMIN_NAME } from 'utils/utils'; +import { ROLE_ADMIN_NAME, GET_IS_USER_LOGGED_IN_URL } from 'utils/utils'; import { IFormInput } from 'components/molecules/UserUpdateForm'; +import axios from 'axios'; export default class UserStore { isUserAuthenticated: boolean = false; @@ -70,8 +71,19 @@ export default class UserStore { }); } - getUserLoginDetails() { - fetchUserInfo() + async getUserLoginDetails() { + let isUserLoggedIn = false; + + await axios.get(GET_IS_USER_LOGGED_IN_URL, { withCredentials: true }) + .then((response) => { + isUserLoggedIn = response.data['is_user_logged_in'] + }).catch((err) => { + console.log('Unable to determine whether user is logged in'); + console.error(err); + }); + + if (isUserLoggedIn){ + fetchUserInfo() .then((userData) => { runInAction(() => { this.userInfo = userData; @@ -85,6 +97,7 @@ export default class UserStore { }); console.error(err); }); + } } async updateUserInfo(formInput: IFormInput) { diff --git a/src/utils/utils.ts b/src/utils/utils.ts index b3539fb0..a441168b 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -39,6 +39,7 @@ export const GET_USERS_INFO_LIST_URL = `${authServerUrl}user/get_all_users_info` export const ADD_ROLE_TO_USER_URL = `${authServerUrl}user/add_to_role`; export const UPDATE_USER_ORG_URL = `${authServerUrl}/user/update_user_org`; export const REMOVE_USER_FROM_ORG_URL = `${authServerUrl}/user/remove_user_from_org`; +export const GET_IS_USER_LOGGED_IN_URL = `${authServerUrl}/user/is_user_logged_in`; AUTH_LOGIN_GOOGLE_URL.searchParams.append('redirect_url', `${window.location.origin}${REDIRECT_ROUTE!}`);