diff --git a/prisma/dev.db b/prisma/dev.db index 076aef0..040db42 100644 Binary files a/prisma/dev.db and b/prisma/dev.db differ diff --git a/src/app/(auth)/login/page.tsx b/src/app/(auth)/login/page.tsx index cee5dc2..1fd3319 100644 --- a/src/app/(auth)/login/page.tsx +++ b/src/app/(auth)/login/page.tsx @@ -1,12 +1,13 @@ "use client"; -import React from "react"; +import React, { useState } from "react"; import axios from "axios"; import LoginForm from "@/components/auth/LoginForm"; const LoginPage: React.FC = () => { + const [error, setError] = useState(""); + const handleLogin = async (email: string, password: string) => { - console.log('Connexion de l\'utilisateur:', email, password); try { const response = await axios.post("/api/auth/login", { @@ -14,15 +15,21 @@ const LoginPage: React.FC = () => { password, }); - console.log('Utilisateur connecté:', response.data); - } catch (error) { - console.error(error); + setError(""); // Reset errors + // Redirect to home page + window.location.href = "/"; + } catch (error: any) { + if (error.response && error.response.status === 400) { + setError("L'adresse e-mail ou le mot de passe est incorrect."); + } else { + setError("Une erreur s'est produite lors de la connexion."); + } } }; return (
- +
); }; diff --git a/src/app/(auth)/signup/page.tsx b/src/app/(auth)/signup/page.tsx index e3fd324..1d5acd5 100644 --- a/src/app/(auth)/signup/page.tsx +++ b/src/app/(auth)/signup/page.tsx @@ -1,12 +1,13 @@ "use client"; -import React from "react"; +import React, { useState } from "react"; import axios from "axios"; import SignupForm from "@/components/auth/SignupForm"; const SignupPage: React.FC = () => { + const [error, setError] = useState(""); + const handleSignup = async (username: string, email: string, password: string) => { - console.log('Création de l\'utilisateur:', username, email, password); try { const response = await axios.post("/api/auth/signup", { @@ -15,15 +16,26 @@ const SignupPage: React.FC = () => { password, }); - console.log('Utilisateur créé:', response.data); - } catch (error) { - console.error(error); + // Redirect to home page + window.location.href = "/"; + } catch (error: any) { + if (error.response && error.response.status === 400) { + if (error.response.data.error === "Username already taken") { + setError("Le nom d'utilisateur est déjà pris."); + } else if (error.response.data.error === "Email already taken") { + setError("L'adresse e-mail est déjà utilisée."); + } else { + setError("Une erreur s'est produite lors de la création de l'utilisateur."); + } + } else { + setError("Une erreur s'est produite lors de la création de l'utilisateur."); + } } }; return (
- +
); }; diff --git a/src/components/auth/LoginForm.tsx b/src/components/auth/LoginForm.tsx index f70c27c..f0a3bb6 100644 --- a/src/components/auth/LoginForm.tsx +++ b/src/components/auth/LoginForm.tsx @@ -4,12 +4,13 @@ import React, { useState } from "react"; interface LoginFormProps { onSubmit: (email: string, password: string) => void; + error: string; + setError: (message: string) => void; } -const LoginForm: React.FC = ({ onSubmit }) => { +const LoginForm: React.FC = ({ onSubmit, error, setError }) => { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); - const [error, setError] = useState(""); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); diff --git a/src/components/auth/SignupForm.tsx b/src/components/auth/SignupForm.tsx index 02539a8..962e952 100644 --- a/src/components/auth/SignupForm.tsx +++ b/src/components/auth/SignupForm.tsx @@ -4,13 +4,14 @@ import React, { useState } from "react"; interface SignupFormProps { onSubmit: (username: string, email: string, password: string) => void; + error: string; + setError: (message: string) => void; } -const SignupForm: React.FC = ({ onSubmit }) => { +const SignupForm: React.FC = ({ onSubmit, error, setError }) => { const [username, setUsername] = useState(""); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); - const [error, setError] = useState(""); const handleSubmit = (e: React.FormEvent) => { e.preventDefault();