fix auth redirect

This commit is contained in:
Romulus21
2024-05-25 15:53:47 +02:00
parent 906db7a908
commit 64e99676ab
2 changed files with 7 additions and 3 deletions

View File

@@ -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'
} }
} }

View File

@@ -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>