diff --git a/src/providers/AuthProvider/AuthProvider.tsx b/src/providers/AuthProvider/AuthProvider.tsx index 3299c48c0..a7b3f71b5 100644 --- a/src/providers/AuthProvider/AuthProvider.tsx +++ b/src/providers/AuthProvider/AuthProvider.tsx @@ -56,13 +56,22 @@ interface AuthProviderProps { loadingComponent?: ReactElement; unauthorizedComponent?: ReactElement; withoutLoader?: boolean; + withoutBackend?: boolean; } +/** + * @param children - ReactNode + * @param loadingComponent - Component to show while auth is loading + * @param unauthorizedComponent - Component to show if user is unauthorized + * @param withoutLoader - Hide loader from AuthProvider + * @param withoutBackend - Will not attempt to get roles from backend + */ export const AuthProvider: FC<AuthProviderProps> = ({ children, loadingComponent, unauthorizedComponent, withoutLoader = false, + withoutBackend = false, }) => { const [account, setAccount] = useState<AccountInfo | undefined>(undefined); const [roles, setRoles] = useState<string[] | undefined>(); @@ -120,6 +129,7 @@ export const AuthProvider: FC<AuthProviderProps> = ({ authState={authState} setAuthState={setAuthState} withoutLoader={withoutLoader} + withoutBackend={withoutBackend} > {children} </AuthProviderInner> diff --git a/src/providers/AuthProvider/AuthProviderInner.tsx b/src/providers/AuthProvider/AuthProviderInner.tsx index f40dbfde7..6499589b2 100644 --- a/src/providers/AuthProvider/AuthProviderInner.tsx +++ b/src/providers/AuthProvider/AuthProviderInner.tsx @@ -47,6 +47,7 @@ export interface AuthProviderInnerProps { withoutLoader: boolean; loadingComponent?: ReactElement; unauthorizedComponent?: ReactElement; + withoutBackend: boolean; } export const AuthProviderInner: FC<AuthProviderInnerProps> = ({ @@ -60,6 +61,7 @@ export const AuthProviderInner: FC<AuthProviderInnerProps> = ({ withoutLoader, loadingComponent, unauthorizedComponent, + withoutBackend, }) => { const { instance, accounts, inProgress } = useMsal(); const { login, result, error, acquireToken } = useMsalAuthentication( @@ -191,7 +193,11 @@ export const AuthProviderInner: FC<AuthProviderInnerProps> = ({ const getPhotoAndRoles = async () => { await getPhoto(); - await getRoles(); + if (withoutBackend) { + setAuthState('authorized'); + } else { + await getRoles(); + } }; getPhotoAndRoles(); @@ -204,6 +210,7 @@ export const AuthProviderInner: FC<AuthProviderInnerProps> = ({ setAuthState, setPhoto, setRoles, + withoutBackend, ]); if (authState === 'unauthorized')