Skip to content

Commit

Permalink
Fix: restricted actions in insecure mode (#3073)
Browse files Browse the repository at this point in the history
  • Loading branch information
darth-coder00 committed Mar 2, 2022
1 parent 6c4bb1f commit d959a49
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Configuration } from '@azure/msal-browser';
import { MsalProvider } from '@azure/msal-react';
import { LoginCallback } from '@okta/okta-react';
import { AxiosError, AxiosResponse } from 'axios';
import { CookieStorage } from 'cookie-storage';
import { isEmpty, isNil } from 'lodash';
import { observer } from 'mobx-react';
import { UserPermissions } from 'Models';
Expand Down Expand Up @@ -66,6 +67,7 @@ interface AuthProviderProps {
children: ReactNode;
}

const cookieStorage = new CookieStorage();
const userAPIQueryFields = 'profile,teams,roles';

export const AuthProvider = ({ children }: AuthProviderProps) => {
Expand Down Expand Up @@ -150,7 +152,16 @@ export const AuthProvider = ({ children }: AuthProviderProps) => {
};

const getUpdatedUser = (data: User, user: OidcUser) => {
const getAdminCookie = localStorage.getItem(isAdminUpdated);
let getAdminCookie = localStorage.getItem(isAdminUpdated);

// TODO: Remove when using cookie no more
if (!getAdminCookie) {
getAdminCookie = cookieStorage.getItem(isAdminUpdated);
if (getAdminCookie) {
localStorage.setItem(isAdminUpdated, getAdminCookie);
}
}

if (getAdminCookie) {
appState.updateUserDetails(data);
} else {
Expand Down Expand Up @@ -366,6 +377,10 @@ export const AuthProvider = ({ children }: AuthProviderProps) => {
);
}, []);

useEffect(() => {
appState.updateAuthState(isAuthDisabled);
}, [isAuthDisabled]);

useEffect(() => {
return history.listen((location) => {
if (!isAuthDisabled && !appState.userDetails) {
Expand Down

0 comments on commit d959a49

Please sign in to comment.