Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get is_user_logged_in from BE #923

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/store/user.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -85,6 +97,7 @@ export default class UserStore {
});
console.error(err);
});
}
}

async updateUserInfo(formInput: IFormInput) {
Expand Down
1 change: 1 addition & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!}`);

Expand Down