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

✨ Added withoutBackend prop to AuthProvider for when only ru… #1031

Merged
merged 1 commit into from
Mar 17, 2025
Merged
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
10 changes: 10 additions & 0 deletions src/providers/AuthProvider/AuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand Down Expand Up @@ -120,6 +129,7 @@ export const AuthProvider: FC<AuthProviderProps> = ({
authState={authState}
setAuthState={setAuthState}
withoutLoader={withoutLoader}
withoutBackend={withoutBackend}
>
{children}
</AuthProviderInner>
Expand Down
9 changes: 8 additions & 1 deletion src/providers/AuthProvider/AuthProviderInner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface AuthProviderInnerProps {
withoutLoader: boolean;
loadingComponent?: ReactElement;
unauthorizedComponent?: ReactElement;
withoutBackend: boolean;
}

export const AuthProviderInner: FC<AuthProviderInnerProps> = ({
Expand All @@ -60,6 +61,7 @@ export const AuthProviderInner: FC<AuthProviderInnerProps> = ({
withoutLoader,
loadingComponent,
unauthorizedComponent,
withoutBackend,
}) => {
const { instance, accounts, inProgress } = useMsal();
const { login, result, error, acquireToken } = useMsalAuthentication(
Expand Down Expand Up @@ -191,7 +193,11 @@ export const AuthProviderInner: FC<AuthProviderInnerProps> = ({

const getPhotoAndRoles = async () => {
await getPhoto();
await getRoles();
if (withoutBackend) {
setAuthState('authorized');
} else {
await getRoles();
}
};

getPhotoAndRoles();
Expand All @@ -204,6 +210,7 @@ export const AuthProviderInner: FC<AuthProviderInnerProps> = ({
setAuthState,
setPhoto,
setRoles,
withoutBackend,
]);

if (authState === 'unauthorized')
Expand Down
Loading