mise a jour

This commit is contained in:
Emma781227
2026-07-01 22:06:22 +02:00
parent efd10d6754
commit 68a9650223
22 changed files with 719 additions and 167 deletions

View File

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