fix auth redirect
This commit is contained in:
@@ -27,11 +27,12 @@ export const AuthUserProvider = ({children}: PropsWithChildren) => {
|
|||||||
try {
|
try {
|
||||||
const res = await axios.get('/api/user')
|
const res = await axios.get('/api/user')
|
||||||
setAuthUser(res.data)
|
setAuthUser(res.data)
|
||||||
} catch (e) {
|
} catch (error) {
|
||||||
// @ts-expect-error check axios response status
|
// @ts-expect-error check axios response status
|
||||||
if (e.response.status === 401) {
|
if (error.response.status === 401) {
|
||||||
console.info('no user login')
|
console.info('no user login')
|
||||||
if (window.location.pathname !== '/connexion') {
|
let url = window.location.pathname.split('/')[1]
|
||||||
|
if (!['connexion', 'changer-le-mot-de-passe'].includes(url)) {
|
||||||
window.location.href = '/connexion'
|
window.location.href = '/connexion'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,9 @@ const Login = () => {
|
|||||||
placeholder="******"
|
placeholder="******"
|
||||||
value={password}
|
value={password}
|
||||||
onChange={event => setPassword(event.target.value)}>Mot de passe</Field>
|
onChange={event => setPassword(event.target.value)}>Mot de passe</Field>
|
||||||
|
<Field type="hidden"
|
||||||
|
name="form_info" onChange={() => setPassword('')} />
|
||||||
|
|
||||||
<button type="submit" className="btn-primary mt-5 block w-full text-lg">Valider</button>
|
<button type="submit" className="btn-primary mt-5 block w-full text-lg">Valider</button>
|
||||||
<Link to="/mot-de-passe-oubliee" className="mt-2 inline-block">Mot de passe oublié ?</Link>
|
<Link to="/mot-de-passe-oubliee" className="mt-2 inline-block">Mot de passe oublié ?</Link>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Reference in New Issue
Block a user