mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2026-01-07 04:56:54 +00:00
fix(ui): notify auth provider for login failed event (#6484)
This commit is contained in:
parent
f276a65612
commit
cc2dcefa6d
@ -557,6 +557,7 @@ export const AuthProvider = ({
|
||||
<MsalProvider instance={msalInstance}>
|
||||
<MsalAuthenticator
|
||||
ref={authenticatorRef}
|
||||
onLoginFailure={handleFailedLogin}
|
||||
onLoginSuccess={handleSuccessfulLogin}
|
||||
onLogoutSuccess={handleSuccessfulLogout}>
|
||||
{children}
|
||||
|
||||
@ -30,10 +30,12 @@ describe('Test MsalAuthenticator component', () => {
|
||||
it('Checks if the MsalAuthenticator renders', async () => {
|
||||
const onLogoutMock = jest.fn();
|
||||
const onLoginMock = jest.fn();
|
||||
const onFailedLoginMock = jest.fn();
|
||||
const authenticatorRef = null;
|
||||
render(
|
||||
<MsalAuthenticator
|
||||
ref={authenticatorRef}
|
||||
onLoginFailure={onFailedLoginMock}
|
||||
onLoginSuccess={onLoginMock}
|
||||
onLogoutSuccess={onLogoutMock}>
|
||||
<p data-testid="children" />
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
|
||||
import { InteractionStatus } from '@azure/msal-browser';
|
||||
import { useAccount, useIsAuthenticated, useMsal } from '@azure/msal-react';
|
||||
import { AxiosError } from 'axios';
|
||||
import React, {
|
||||
forwardRef,
|
||||
Fragment,
|
||||
@ -32,11 +33,15 @@ import {
|
||||
interface Props {
|
||||
children: ReactNode;
|
||||
onLoginSuccess: (user: OidcUser) => void;
|
||||
onLoginFailure: (error: AxiosError) => void;
|
||||
onLogoutSuccess: () => void;
|
||||
}
|
||||
|
||||
const MsalAuthenticator = forwardRef<AuthenticatorRef, Props>(
|
||||
({ children, onLoginSuccess, onLogoutSuccess }: Props, ref) => {
|
||||
(
|
||||
{ children, onLoginSuccess, onLogoutSuccess, onLoginFailure }: Props,
|
||||
ref
|
||||
) => {
|
||||
const { setIsAuthenticated, loading, setLoadingIndicator } =
|
||||
useAuthContext();
|
||||
const { instance, accounts, inProgress } = useMsal();
|
||||
@ -115,6 +120,7 @@ const MsalAuthenticator = forwardRef<AuthenticatorRef, Props>(
|
||||
onLoginSuccess(user as OidcUser);
|
||||
}
|
||||
})
|
||||
.catch(onLoginFailure)
|
||||
.finally(() => {
|
||||
if (loading) {
|
||||
setLoadingIndicator(false);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user