mise a jour
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import { useState } from 'react'
|
||||
import { Link, useNavigate, useLocation } from 'react-router-dom'
|
||||
import { loginApi } from '../services/auth'
|
||||
import { useAuth } from '../context/AuthContext'
|
||||
|
||||
export default function Connexion() {
|
||||
const navigate = useNavigate()
|
||||
const location = useLocation()
|
||||
const { login } = useAuth()
|
||||
const justRegistered = location.state?.registered === true
|
||||
const [form, setForm] = useState({ email: '', password: '' })
|
||||
const [showPassword, setShowPassword] = useState(false)
|
||||
@@ -19,8 +21,7 @@ export default function Connexion() {
|
||||
setLoading(true)
|
||||
try {
|
||||
const { token, user } = await loginApi(form)
|
||||
localStorage.setItem('token', token)
|
||||
localStorage.setItem('user', JSON.stringify(user))
|
||||
login(user, token)
|
||||
if (user.role === 'ADMIN') navigate('/admin')
|
||||
else if (user.role === 'EMPLOYEE') navigate('/employe')
|
||||
else navigate('/mes-gains')
|
||||
|
||||
Reference in New Issue
Block a user