-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
120 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
<link rel="apple-touch-icon" href="/dsfr/favicon/apple-touch-icon.png?v=1.12.1" /> | ||
<link rel="icon" href="/dsfr/favicon/favicon.svg?v=1.12.1" type="image/svg+xml" /> | ||
<link rel="shortcut icon" href="/dsfr/favicon/favicon.ico?v=1.12.1" type="image/x-icon" /> | ||
<link rel="stylesheet" href="/dsfr/utility/icons/icons.min.css?hash=f2a5db63" /> | ||
<link rel="stylesheet" href="/dsfr/utility/icons/icons.min.css?hash=29be53c3" /> | ||
<link rel="stylesheet" href="/dsfr/dsfr.min.css?v=1.12.1" /> | ||
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/maplibre-gl.css" /> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 78 additions & 15 deletions
93
frontend/src/views/LoginCallbackView/LoginCallbackView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,92 @@ | ||
import { useEffect } from 'react'; | ||
import Alert from '@codegouvfr/react-dsfr/Alert'; | ||
import Button from '@codegouvfr/react-dsfr/Button'; | ||
import { cx } from '@codegouvfr/react-dsfr/fr/cx'; | ||
import clsx from 'clsx'; | ||
import { useEffect, useRef } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { useAppDispatch } from 'src/hooks/useStore'; | ||
import { useAuthenticateMutation } from 'src/services/auth.service'; | ||
import authSlice from 'src/store/reducers/authSlice'; | ||
|
||
export const LoginCallbackView = () => { | ||
const dispatch = useAppDispatch(); | ||
const [authenticate] = useAuthenticateMutation(); | ||
const [authenticate, { isLoading, isSuccess, isError, data: authUser }] = | ||
useAuthenticateMutation(); | ||
const navigate = useNavigate(); | ||
|
||
const hasAuthenticatedRef = useRef(false); | ||
|
||
useEffect(() => { | ||
if (hasAuthenticatedRef.current) { | ||
return; | ||
} | ||
hasAuthenticatedRef.current = true; | ||
|
||
authenticate({ | ||
url: window.location.href, | ||
nonce: sessionStorage.getItem('nonce'), | ||
state: sessionStorage.getItem('state') | ||
}); | ||
}, []); // eslint-disable-line react-hooks/exhaustive-deps | ||
|
||
useEffect(() => { | ||
(() => | ||
authenticate({ | ||
url: window.location.href, | ||
nonce: sessionStorage.getItem('nonce') || '', | ||
state: sessionStorage.getItem('state') || '' | ||
}) | ||
.unwrap() | ||
.then((authUser) => { | ||
dispatch(authSlice.actions.signinUser({ authUser })); | ||
navigate('/'); | ||
}))(); | ||
}, [window.location.href]); // eslint-disable-line react-hooks/exhaustive-deps | ||
if (isSuccess && authUser) { | ||
dispatch(authSlice.actions.signinUser({ authUser })); | ||
navigate('/'); | ||
} | ||
}, [ | ||
isSuccess, | ||
authUser | ||
]) /* eslint-disable-line react-hooks/exhaustive-deps */; | ||
|
||
return <div>Connexion ... Merci de patienter....</div>; | ||
return ( | ||
<section className={clsx(cx('fr-container-sm'), 'main-section')}> | ||
{isLoading && ( | ||
<Alert | ||
severity="info" | ||
title="Connexion en cours" | ||
description={ | ||
<> | ||
<div className={cx('fr-pt-1w', 'fr-pb-3w')}> | ||
Merci de patienter... | ||
</div> | ||
<Button | ||
linkProps={{ | ||
to: '/' | ||
}} | ||
priority="tertiary no outline" | ||
className={clsx(cx('fr-link'), 'link-underline')} | ||
> | ||
Retour à l'accueil | ||
</Button> | ||
</> | ||
} | ||
></Alert> | ||
)} | ||
{isError && ( | ||
<Alert | ||
severity="error" | ||
title="Erreur de connexion" | ||
description={ | ||
<> | ||
<div className={cx('fr-pt-1w', 'fr-pb-3w')}> | ||
Une erreur est survenue lors de la connexion. | ||
</div> | ||
<Button | ||
linkProps={{ | ||
to: '/' | ||
}} | ||
priority="tertiary no outline" | ||
className={clsx(cx('fr-link'), 'link-underline')} | ||
> | ||
Retour à l'accueil | ||
</Button> | ||
</> | ||
} | ||
></Alert> | ||
)} | ||
</section> | ||
); | ||
}; | ||
|
||
export default LoginCallbackView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.