Les routes et les contrôleurs backend pour l'inscription, la connexion et la déconnexion des utilisateurs

This commit is contained in:
el 2025-05-18 00:46:52 +02:00
parent 37ffb163d7
commit f4ab9b3d15
52 changed files with 10487 additions and 0 deletions

View file

@ -0,0 +1 @@
NEXT_PUBLIC_API_URL=http://localhost/api

36
frontend/.gitignore vendored Normal file
View file

@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# local env files
.env*.local
.env
# vercel
.vercel
# typescript
*.tsbuildinfo
next-env.d.ts

36
frontend/README.md Normal file
View file

@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
## Getting Started
First, run the development server:
```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
## Learn More
To learn more about Next.js, take a look at the following resources:
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
## Deploy on Vercel
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.

View file

@ -0,0 +1,16 @@
import { dirname } from "path";
import { fileURLToPath } from "url";
import { FlatCompat } from "@eslint/eslintrc";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
});
const eslintConfig = [
...compat.extends("next/core-web-vitals", "next/typescript"),
];
export default eslintConfig;

7
frontend/next.config.ts Normal file
View file

@ -0,0 +1,7 @@
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
/* config options here */
};
export default nextConfig;

6160
frontend/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

29
frontend/package.json Normal file
View file

@ -0,0 +1,29 @@
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"axios": "^1.9.0",
"next": "15.3.2",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"zustand": "^5.0.4"
},
"devDependencies": {
"@eslint/eslintrc": "^3",
"@tailwindcss/postcss": "^4",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"eslint": "^9",
"eslint-config-next": "15.3.2",
"tailwindcss": "^4",
"typescript": "^5"
}
}

View file

@ -0,0 +1,5 @@
const config = {
plugins: ["@tailwindcss/postcss"],
};
export default config;

1
frontend/public/file.svg Normal file
View file

@ -0,0 +1 @@
<svg fill="none" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M14.5 13.5V5.41a1 1 0 0 0-.3-.7L9.8.29A1 1 0 0 0 9.08 0H1.5v13.5A2.5 2.5 0 0 0 4 16h8a2.5 2.5 0 0 0 2.5-2.5m-1.5 0v-7H8v-5H3v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1M9.5 5V2.12L12.38 5zM5.13 5h-.62v1.25h2.12V5zm-.62 3h7.12v1.25H4.5zm.62 3h-.62v1.25h7.12V11z" clip-rule="evenodd" fill="#666" fill-rule="evenodd"/></svg>

After

Width:  |  Height:  |  Size: 391 B

View file

@ -0,0 +1 @@
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.27 14.1a6.5 6.5 0 0 0 3.67-3.45q-1.24.21-2.7.34-.31 1.83-.97 3.1M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m.48-1.52a7 7 0 0 1-.96 0H7.5a4 4 0 0 1-.84-1.32q-.38-.89-.63-2.08a40 40 0 0 0 3.92 0q-.25 1.2-.63 2.08a4 4 0 0 1-.84 1.31zm2.94-4.76q1.66-.15 2.95-.43a7 7 0 0 0 0-2.58q-1.3-.27-2.95-.43a18 18 0 0 1 0 3.44m-1.27-3.54a17 17 0 0 1 0 3.64 39 39 0 0 1-4.3 0 17 17 0 0 1 0-3.64 39 39 0 0 1 4.3 0m1.1-1.17q1.45.13 2.69.34a6.5 6.5 0 0 0-3.67-3.44q.65 1.26.98 3.1M8.48 1.5l.01.02q.41.37.84 1.31.38.89.63 2.08a40 40 0 0 0-3.92 0q.25-1.2.63-2.08a4 4 0 0 1 .85-1.32 7 7 0 0 1 .96 0m-2.75.4a6.5 6.5 0 0 0-3.67 3.44 29 29 0 0 1 2.7-.34q.31-1.83.97-3.1M4.58 6.28q-1.66.16-2.95.43a7 7 0 0 0 0 2.58q1.3.27 2.95.43a18 18 0 0 1 0-3.44m.17 4.71q-1.45-.12-2.69-.34a6.5 6.5 0 0 0 3.67 3.44q-.65-1.27-.98-3.1" fill="#666"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>

After

Width:  |  Height:  |  Size: 1 KiB

1
frontend/public/next.svg Normal file
View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -0,0 +1 @@
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1155 1000"><path d="m577.3 0 577.4 1000H0z" fill="#fff"/></svg>

After

Width:  |  Height:  |  Size: 128 B

View file

@ -0,0 +1 @@
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 2.5h13v10a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1zM0 1h16v11.5a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 12.5zm3.75 4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5M7 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m1.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5" fill="#666"/></svg>

After

Width:  |  Height:  |  Size: 385 B

View file

@ -0,0 +1,47 @@
.authContainer {
max-width: 800px;
margin: 2rem auto;
padding: 1rem;
}
.authTabs {
display: flex;
justify-content: center;
gap: 1rem;
margin-bottom: 2rem;
}
.tabButton {
padding: 0.75rem 2rem;
font-size: 1rem;
border: none;
border-radius: 4px;
background-color: #f8f9fa;
color: #495057;
cursor: pointer;
transition: all 0.2s;
}
.tabButton:hover {
background-color: #e9ecef;
}
.tabButton.active {
background-color: #4a90e2;
color: white;
}
.formWrapper {
animation: fadeIn 0.3s ease-in-out;
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}

View file

@ -0,0 +1,33 @@
'use client';
import { useState } from 'react';
import LoginForm from '@/components/auth/LoginForm';
import RegisterForm from '@/components/auth/RegisterForm';
import styles from './auth.module.css';
export default function AuthPage() {
const [activeTab, setActiveTab] = useState<'login' | 'register'>('login');
return (
<div className={styles.authContainer}>
<div className={styles.authTabs}>
<button
className={`${styles.tabButton} ${activeTab === 'login' ? styles.active : ''}`}
onClick={() => setActiveTab('login')}
>
Connexion
</button>
<button
className={`${styles.tabButton} ${activeTab === 'register' ? styles.active : ''}`}
onClick={() => setActiveTab('register')}
>
Inscription
</button>
</div>
<div className={styles.formWrapper}>
{activeTab === 'login' ? <LoginForm /> : <RegisterForm />}
</div>
</div>
);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

View file

@ -0,0 +1,26 @@
@import "tailwindcss";
:root {
--background: #ffffff;
--foreground: #171717;
}
@theme inline {
--color-background: var(--background);
--color-foreground: var(--foreground);
--font-sans: var(--font-geist-sans);
--font-mono: var(--font-geist-mono);
}
@media (prefers-color-scheme: dark) {
:root {
--background: #0a0a0a;
--foreground: #ededed;
}
}
body {
background: var(--background);
color: var(--foreground);
font-family: Arial, Helvetica, sans-serif;
}

View file

@ -0,0 +1,34 @@
import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import "./globals.css";
const geistSans = Geist({
variable: "--font-geist-sans",
subsets: ["latin"],
});
const geistMono = Geist_Mono({
variable: "--font-geist-mono",
subsets: ["latin"],
});
export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
{children}
</body>
</html>
);
}

View file

@ -0,0 +1,51 @@
.main {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
background: linear-gradient(135deg, #4a90e2 0%, #357abd 100%);
color: white;
text-align: center;
padding: 2rem;
}
.content {
max-width: 800px;
margin: 0 auto;
}
.main h1 {
font-size: 4rem;
font-weight: bold;
margin-bottom: 1rem;
letter-spacing: -0.02em;
}
.subtitle {
font-size: 1.5rem;
margin-bottom: 3rem;
opacity: 0.9;
}
.cta {
margin-top: 2rem;
}
.ctaButton {
display: inline-block;
padding: 1rem 2rem;
font-size: 1.2rem;
background-color: white;
color: #4a90e2;
text-decoration: none;
border-radius: 8px;
transition: all 0.2s;
font-weight: 500;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.ctaButton:hover {
transform: translateY(-2px);
box-shadow: 0 6px 8px rgba(0, 0, 0, 0.2);
}

19
frontend/src/app/page.tsx Normal file
View file

@ -0,0 +1,19 @@
import Link from 'next/link';
import styles from './page.module.css';
export default function Home() {
return (
<main className={styles.main}>
<div className={styles.content}>
<h1>WeMusic</h1>
<p className={styles.subtitle}>La plateforme pour les artistes indépendants</p>
<div className={styles.cta}>
<Link href="/auth" className={styles.ctaButton}>
Connexion / Inscription
</Link>
</div>
</div>
</main>
);
}

View file

@ -0,0 +1,63 @@
'use client';
import { useState, useEffect } from 'react';
import axios from 'axios';
interface ApiResponse {
message: string;
timestamp: string;
}
export default function TestApi() {
const [response, setResponse] = useState<ApiResponse | null>(null);
const [error, setError] = useState<string>('');
const [loading, setLoading] = useState<boolean>(true);
useEffect(() => {
const fetchData = async () => {
try {
const apiUrl = process.env.NEXT_PUBLIC_API_URL;
if (!apiUrl) {
throw new Error('L\'URL de l\'API n\'est pas configurée');
}
const result = await axios.get<ApiResponse>(`${apiUrl}/test`);
setResponse(result.data);
setError('');
} catch (err) {
setError('Erreur lors de la connexion à l\'API: ' + (err instanceof Error ? err.message : 'Erreur inconnue'));
setResponse(null);
} finally {
setLoading(false);
}
};
fetchData();
}, []);
if (loading) {
return <div className="flex items-center justify-center p-4">Chargement...</div>;
}
if (error) {
return (
<div className="p-4 bg-red-100 border border-red-400 text-red-700 rounded">
{error}
</div>
);
}
return (
<div className="p-4 bg-white shadow rounded">
<h2 className="text-xl font-bold mb-4 text-gray-800">Test de Connexion API</h2>
{response && (
<div className="space-y-2">
<p className="text-green-600">{response.message}</p>
<p className="text-sm text-gray-500">
Timestamp: {new Date(response.timestamp).toLocaleString()}
</p>
</div>
)}
</div>
);
}

View file

@ -0,0 +1,113 @@
.formContainer {
max-width: 500px;
margin: 2rem auto;
padding: 2rem;
background-color: #ffffff;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.formContainer h2 {
margin-bottom: 1.5rem;
color: #333;
text-align: center;
}
.form {
display: flex;
flex-direction: column;
gap: 1rem;
}
.formGroup {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.formGroup label {
color: #555;
font-size: 0.9rem;
}
.formGroup input,
.formGroup select,
.formGroup textarea {
padding: 0.75rem;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 1rem;
transition: border-color 0.2s;
}
.formGroup input:focus,
.formGroup select:focus,
.formGroup textarea:focus {
border-color: #4a90e2;
outline: none;
box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.1);
}
.formGroup textarea {
resize: vertical;
min-height: 100px;
}
.error {
color: #dc3545;
font-size: 0.9rem;
margin-top: 0.5rem;
padding: 0.5rem;
background-color: rgba(220, 53, 69, 0.1);
border-radius: 4px;
}
.success {
color: #28a745;
font-size: 0.9rem;
margin-top: 0.5rem;
padding: 0.5rem;
background-color: rgba(40, 167, 69, 0.1);
border-radius: 4px;
}
.submitButton {
margin-top: 1rem;
padding: 0.75rem;
background-color: #4a90e2;
color: white;
border: none;
border-radius: 4px;
font-size: 1rem;
cursor: pointer;
transition: background-color 0.2s;
}
.submitButton:hover:not(:disabled) {
background-color: #357abd;
}
.submitButton:disabled {
background-color: #ccc;
cursor: not-allowed;
}
.userInfo {
margin-top: 2rem;
padding: 1rem;
background-color: #f8f9fa;
border-radius: 4px;
border: 1px solid #e9ecef;
}
.userInfo h3 {
color: #4a90e2;
margin-bottom: 1rem;
font-size: 1.1rem;
}
.userInfo p {
margin: 0.5rem 0;
color: #495057;
font-size: 0.9rem;
}

View file

@ -0,0 +1,137 @@
'use client';
import { useState, FormEvent } from 'react';
import styles from './AuthForms.module.css';
import useAuthStore from '@/store/useAuthStore';
import type { User } from '@/store/useAuthStore';
interface LoginFormData {
email: string;
password: string;
}
interface LoginResponse {
success: boolean;
message: string;
token: string;
user: User;
}
export default function LoginForm() {
// État du formulaire
const [formData, setFormData] = useState<LoginFormData>({
email: '',
password: ''
});
// État des erreurs et du message de succès
const [error, setError] = useState<string>('');
const [success, setSuccess] = useState<string>('');
const [isLoading, setIsLoading] = useState<boolean>(false);
// Récupération des fonctions du store
const { setUser, user, isAuthenticated } = useAuthStore();
// Gestion des changements dans les champs
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const { name, value } = e.target;
setFormData(prev => ({
...prev,
[name]: value
}));
};
// Soumission du formulaire
const handleSubmit = async (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
setError('');
setSuccess('');
setIsLoading(true);
try {
// Validation basique
if (!formData.email || !formData.password) {
throw new Error('Veuillez remplir tous les champs');
}
// Appel à l'API
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/auth/login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(formData)
});
const data: LoginResponse = await response.json();
if (!response.ok) {
throw new Error(data.message || 'Une erreur est survenue');
}
// Mise à jour du store avec les informations de l'utilisateur
setUser(data.user, data.token);
setSuccess('Connexion réussie !');
} catch (err) {
setError(err instanceof Error ? err.message : 'Une erreur est survenue');
} finally {
setIsLoading(false);
}
};
return (
<div className={styles.formContainer}>
<h2>Connexion</h2>
<form onSubmit={handleSubmit} className={styles.form}>
<div className={styles.formGroup}>
<label htmlFor="email">Email</label>
<input
type="email"
id="email"
name="email"
value={formData.email}
onChange={handleChange}
placeholder="votre@email.com"
required
/>
</div>
<div className={styles.formGroup}>
<label htmlFor="password">Mot de passe</label>
<input
type="password"
id="password"
name="password"
value={formData.password}
onChange={handleChange}
placeholder="Votre mot de passe"
required
/>
</div>
{error && <div className={styles.error}>{error}</div>}
{success && <div className={styles.success}>{success}</div>}
<button
type="submit"
className={styles.submitButton}
disabled={isLoading}
>
{isLoading ? 'Connexion...' : 'Se connecter'}
</button>
</form>
{/* Affichage des informations de l'utilisateur connecté */}
{isAuthenticated && user && (
<div className={styles.userInfo}>
<h3>Utilisateur connecté :</h3>
<p>Nom : {user.artist_name}</p>
<p>Email : {user.email}</p>
<p>Type : {user.user_type}</p>
</div>
)}
</div>
);
}

View file

@ -0,0 +1,250 @@
'use client';
import { useState, FormEvent } from 'react';
import styles from './AuthForms.module.css';
import useAuthStore from '@/store/useAuthStore';
import type { User } from '@/store/useAuthStore';
interface RegisterFormData {
email: string;
password: string;
confirmPassword: string;
artist_name: string;
user_type: 'artist' | 'venue_owner' | 'partner' | 'admin';
bio_short?: string;
bio_long?: string;
}
interface RegisterResponse {
success: boolean;
message: string;
token: string;
user: User;
}
export default function RegisterForm() {
// État du formulaire
const [formData, setFormData] = useState<RegisterFormData>({
email: '',
password: '',
confirmPassword: '',
artist_name: '',
user_type: 'artist',
bio_short: '',
bio_long: ''
});
// État des erreurs et du message de succès
const [error, setError] = useState<string>('');
const [success, setSuccess] = useState<string>('');
const [isLoading, setIsLoading] = useState<boolean>(false);
// Récupération des fonctions du store
const { setUser, user, isAuthenticated } = useAuthStore();
// Gestion des changements dans les champs
const handleChange = (
e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>
) => {
const { name, value } = e.target;
setFormData(prev => ({
...prev,
[name]: value
}));
};
// Validation du formulaire
const validateForm = (): string | null => {
if (!formData.email || !formData.password || !formData.confirmPassword || !formData.artist_name) {
return 'Veuillez remplir tous les champs obligatoires';
}
if (formData.password !== formData.confirmPassword) {
return 'Les mots de passe ne correspondent pas';
}
if (formData.password.length < 8) {
return 'Le mot de passe doit contenir au moins 8 caractères';
}
return null;
};
// Soumission du formulaire
const handleSubmit = async (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
setError('');
setSuccess('');
setIsLoading(true);
// Validation
const validationError = validateForm();
if (validationError) {
setError(validationError);
setIsLoading(false);
return;
}
try {
// Préparation des données pour l'API
const apiData = {
...formData,
confirmPassword: undefined
};
delete apiData.confirmPassword;
// Appel à l'API
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/auth/register`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(apiData)
});
const data: RegisterResponse = await response.json();
if (!response.ok) {
throw new Error(data.message || 'Une erreur est survenue');
}
// Mise à jour du store avec les informations de l'utilisateur
setUser(data.user, data.token);
setSuccess('Inscription réussie !');
// Réinitialisation du formulaire
setFormData({
email: '',
password: '',
confirmPassword: '',
artist_name: '',
user_type: 'artist',
bio_short: '',
bio_long: ''
});
} catch (err) {
setError(err instanceof Error ? err.message : 'Une erreur est survenue');
} finally {
setIsLoading(false);
}
};
return (
<div className={styles.formContainer}>
<h2>Inscription</h2>
<form onSubmit={handleSubmit} className={styles.form}>
<div className={styles.formGroup}>
<label htmlFor="email">Email *</label>
<input
type="email"
id="email"
name="email"
value={formData.email}
onChange={handleChange}
placeholder="votre@email.com"
required
/>
</div>
<div className={styles.formGroup}>
<label htmlFor="password">Mot de passe *</label>
<input
type="password"
id="password"
name="password"
value={formData.password}
onChange={handleChange}
placeholder="Minimum 8 caractères"
required
/>
</div>
<div className={styles.formGroup}>
<label htmlFor="confirmPassword">Confirmer le mot de passe *</label>
<input
type="password"
id="confirmPassword"
name="confirmPassword"
value={formData.confirmPassword}
onChange={handleChange}
placeholder="Confirmez votre mot de passe"
required
/>
</div>
<div className={styles.formGroup}>
<label htmlFor="artist_name">Nom d'artiste *</label>
<input
type="text"
id="artist_name"
name="artist_name"
value={formData.artist_name}
onChange={handleChange}
placeholder="Votre nom d'artiste"
required
/>
</div>
<div className={styles.formGroup}>
<label htmlFor="user_type">Type d'utilisateur *</label>
<select
id="user_type"
name="user_type"
value={formData.user_type}
onChange={handleChange}
required
>
<option value="artist">Artiste</option>
<option value="venue_owner">Propriétaire de salle</option>
<option value="partner">Partenaire</option>
<option value="admin">Administrateur</option>
</select>
</div>
<div className={styles.formGroup}>
<label htmlFor="bio_short">Courte biographie</label>
<input
type="text"
id="bio_short"
name="bio_short"
value={formData.bio_short}
onChange={handleChange}
placeholder="Une brève description de vous"
/>
</div>
<div className={styles.formGroup}>
<label htmlFor="bio_long">Biographie détaillée</label>
<textarea
id="bio_long"
name="bio_long"
value={formData.bio_long}
onChange={handleChange}
placeholder="Parlez-nous de vous en détail"
rows={4}
/>
</div>
{error && <div className={styles.error}>{error}</div>}
{success && <div className={styles.success}>{success}</div>}
<button
type="submit"
className={styles.submitButton}
disabled={isLoading}
>
{isLoading ? 'Inscription...' : 'S\'inscrire'}
</button>
</form>
{/* Affichage des informations de l'utilisateur inscrit */}
{isAuthenticated && user && (
<div className={styles.userInfo}>
<h3>Inscription réussie !</h3>
<p>Nom : {user.artist_name}</p>
<p>Email : {user.email}</p>
<p>Type : {user.user_type}</p>
</div>
)}
</div>
);
}

View file

@ -0,0 +1,59 @@
import { create } from 'zustand';
import { persist } from 'zustand/middleware';
// Interface pour l'utilisateur
export interface User {
id: string;
email: string;
artist_name: string;
user_type: 'artist' | 'venue_owner' | 'partner' | 'admin';
bio_short?: string;
bio_long?: string;
profile_picture_url?: string;
created_at: string;
updated_at?: string;
}
// Interface pour le store d'authentification
interface AuthState {
user: User | null;
token: string | null;
isAuthenticated: boolean;
setUser: (user: User, token: string) => void;
clearUser: () => void;
}
// Création du store avec persistance
const useAuthStore = create<AuthState>()(
persist(
(set) => ({
user: null,
token: null,
isAuthenticated: false,
// Définir l'utilisateur et le token
setUser: (user: User, token: string) => set({
user,
token,
isAuthenticated: true
}),
// Réinitialiser l'état
clearUser: () => set({
user: null,
token: null,
isAuthenticated: false
})
}),
{
name: 'auth-storage', // Nom du stockage dans le localStorage
partialize: (state) => ({
user: state.user,
token: state.token,
isAuthenticated: state.isAuthenticated
})
}
)
);
export default useAuthStore;

27
frontend/tsconfig.json Normal file
View file

@ -0,0 +1,27 @@
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}