feat: improve auth flow
All checks were successful
Deploy to Netlify / Deploy to Netlify (push) Successful in 2m8s
All checks were successful
Deploy to Netlify / Deploy to Netlify (push) Successful in 2m8s
This commit is contained in:
parent
053316ebef
commit
135058e2e1
3 changed files with 9 additions and 5 deletions
|
|
@ -68,7 +68,7 @@ export default function Profile({ user }: { user: User }) {
|
|||
<Button
|
||||
variant="destructive"
|
||||
className="w-full text-white"
|
||||
onClick={logout}
|
||||
onClick={handleLogout}
|
||||
>
|
||||
<LogOut className="mr-2 h-4 w-4" />
|
||||
Se déconnecter
|
||||
|
|
|
|||
|
|
@ -68,13 +68,13 @@ export const getClasses = async () => {
|
|||
};
|
||||
|
||||
export const registerUser = async (
|
||||
name: string,
|
||||
userId: number,
|
||||
className: string,
|
||||
token: string
|
||||
) => {
|
||||
return makePostRequest(
|
||||
"/auth/register",
|
||||
{ name, className, token },
|
||||
{ userId, className, token },
|
||||
"Échec de l'inscription"
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ export default function Register() {
|
|||
const [error, setError] = useState<string | null>(null);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const [names, setNames] = useState<{ value: string; label: string }[]>([]);
|
||||
const [names, setNames] = useState<{ value: string; label: string, userId: number }[]>([]);
|
||||
const hasSubmitted = names.length > 0;
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
|
|
@ -84,7 +84,11 @@ export default function Register() {
|
|||
} else {
|
||||
// Register user
|
||||
if (!name) return setError("Veuillez compléter votre nom.");
|
||||
await registerUser(name, className, token!)
|
||||
const userId = names.find(
|
||||
(n) => n.value === name
|
||||
)?.userId;
|
||||
if (!userId) return setError("Une erreur est survenue, veuillez réessayer.");
|
||||
await registerUser(userId, className, token!)
|
||||
.then(() => {
|
||||
setIsLoading(false);
|
||||
navigate("/", {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue