Checkpoint: Migration OAuth Manus vers authentification locale (80% complété) - Pages login/register créées, backend JWT implémenté, guides de déploiement ajoutés. Reste à corriger les doublons dans db.ts et finaliser AdminUsers.

This commit is contained in:
Manus Sandbox
2025-11-19 04:39:07 -05:00
parent 9d67724e83
commit 28727171ae
17 changed files with 2168 additions and 87 deletions

View File

@@ -15,10 +15,14 @@ import AdminUsers from "./pages/AdminUsers";
import AdminEmailTemplates from "./pages/AdminEmailTemplates";
import AdminEmailConfig from "./pages/AdminEmailConfig";
import Inscription from "./pages/Inscription";
import Login from "./pages/Login";
import Register from "./pages/Register";
function Router() {
return (
<Switch>
<Route path={"/login"} component={Login} />
<Route path={"/register"} component={Register} />
<Route path={"/"} component={Home} />
<Route path={"/admin/rapport-public-cible"} component={AdminRapportPublicCible} />
<Route path={"/inscription/:lien"} component={Inscription} />

View File

@@ -4,18 +4,5 @@ export const APP_TITLE = import.meta.env.VITE_APP_TITLE || "App";
export const APP_LOGO = "https://placehold.co/128x128/E1E7EF/1F2937?text=App";
// Generate login URL at runtime so redirect URI reflects the current origin.
export const getLoginUrl = () => {
const oauthPortalUrl = import.meta.env.VITE_OAUTH_PORTAL_URL;
const appId = import.meta.env.VITE_APP_ID;
const redirectUri = `${window.location.origin}/api/oauth/callback`;
const state = btoa(redirectUri);
const url = new URL(`${oauthPortalUrl}/app-auth`);
url.searchParams.set("appId", appId);
url.searchParams.set("redirectUri", redirectUri);
url.searchParams.set("state", state);
url.searchParams.set("type", "signIn");
return url.toString();
};
// Retourne l'URL de la page de connexion locale
export const getLoginUrl = () => "/login";

116
client/src/pages/Login.tsx Normal file
View File

@@ -0,0 +1,116 @@
import { useState } from "react";
import { useLocation } from "wouter";
import { trpc } from "@/lib/trpc";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
import { Alert, AlertDescription } from "@/components/ui/alert";
import { APP_LOGO, APP_TITLE } from "@/const";
import { Loader2 } from "lucide-react";
export default function Login() {
const [, setLocation] = useLocation();
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [error, setError] = useState("");
const loginMutation = trpc.auth.login.useMutation({
onSuccess: () => {
// Rediriger vers le tableau de bord
window.location.href = "/";
},
onError: (error) => {
setError(error.message);
},
});
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
setError("");
if (!email || !password) {
setError("Veuillez remplir tous les champs");
return;
}
loginMutation.mutate({ email, password });
};
return (
<div className="min-h-screen flex items-center justify-center bg-gradient-to-br from-blue-50 to-indigo-100 p-4">
<Card className="w-full max-w-md">
<CardHeader className="space-y-1 text-center">
{APP_LOGO && (
<div className="flex justify-center mb-4">
<img src={APP_LOGO} alt={APP_TITLE} className="h-16 w-auto" />
</div>
)}
<CardTitle className="text-2xl font-bold">{APP_TITLE}</CardTitle>
<CardDescription>
Connectez-vous à votre compte
</CardDescription>
</CardHeader>
<form onSubmit={handleSubmit}>
<CardContent className="space-y-4">
{error && (
<Alert variant="destructive">
<AlertDescription>{error}</AlertDescription>
</Alert>
)}
<div className="space-y-2">
<Label htmlFor="email">Email</Label>
<Input
id="email"
type="email"
placeholder="votre@email.com"
value={email}
onChange={(e) => setEmail(e.target.value)}
disabled={loginMutation.isPending}
required
/>
</div>
<div className="space-y-2">
<Label htmlFor="password">Mot de passe</Label>
<Input
id="password"
type="password"
placeholder="••••••••"
value={password}
onChange={(e) => setPassword(e.target.value)}
disabled={loginMutation.isPending}
required
/>
</div>
</CardContent>
<CardFooter className="flex flex-col space-y-4">
<Button
type="submit"
className="w-full"
disabled={loginMutation.isPending}
>
{loginMutation.isPending && (
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
)}
Se connecter
</Button>
<div className="text-sm text-center text-muted-foreground">
Pas encore de compte ?{" "}
<button
type="button"
onClick={() => setLocation("/register")}
className="text-primary hover:underline font-medium"
>
S'inscrire
</button>
</div>
</CardFooter>
</form>
</Card>
</div>
);
}

View File

@@ -0,0 +1,156 @@
import { useState } from "react";
import { useLocation } from "wouter";
import { trpc } from "@/lib/trpc";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
import { Alert, AlertDescription } from "@/components/ui/alert";
import { APP_LOGO, APP_TITLE } from "@/const";
import { Loader2 } from "lucide-react";
export default function Register() {
const [, setLocation] = useLocation();
const [name, setName] = useState("");
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [confirmPassword, setConfirmPassword] = useState("");
const [error, setError] = useState("");
const registerMutation = trpc.auth.register.useMutation({
onSuccess: () => {
// Rediriger vers le tableau de bord
window.location.href = "/";
},
onError: (error) => {
setError(error.message);
},
});
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
setError("");
if (!email || !password || !confirmPassword) {
setError("Veuillez remplir tous les champs obligatoires");
return;
}
if (password.length < 6) {
setError("Le mot de passe doit contenir au moins 6 caractères");
return;
}
if (password !== confirmPassword) {
setError("Les mots de passe ne correspondent pas");
return;
}
registerMutation.mutate({ email, password, name: name || undefined });
};
return (
<div className="min-h-screen flex items-center justify-center bg-gradient-to-br from-blue-50 to-indigo-100 p-4">
<Card className="w-full max-w-md">
<CardHeader className="space-y-1 text-center">
{APP_LOGO && (
<div className="flex justify-center mb-4">
<img src={APP_LOGO} alt={APP_TITLE} className="h-16 w-auto" />
</div>
)}
<CardTitle className="text-2xl font-bold">Créer un compte</CardTitle>
<CardDescription>
Inscrivez-vous pour accéder à {APP_TITLE}
</CardDescription>
</CardHeader>
<form onSubmit={handleSubmit}>
<CardContent className="space-y-4">
{error && (
<Alert variant="destructive">
<AlertDescription>{error}</AlertDescription>
</Alert>
)}
<div className="space-y-2">
<Label htmlFor="name">Nom (optionnel)</Label>
<Input
id="name"
type="text"
placeholder="Votre nom"
value={name}
onChange={(e) => setName(e.target.value)}
disabled={registerMutation.isPending}
/>
</div>
<div className="space-y-2">
<Label htmlFor="email">Email *</Label>
<Input
id="email"
type="email"
placeholder="votre@email.com"
value={email}
onChange={(e) => setEmail(e.target.value)}
disabled={registerMutation.isPending}
required
/>
</div>
<div className="space-y-2">
<Label htmlFor="password">Mot de passe *</Label>
<Input
id="password"
type="password"
placeholder="••••••••"
value={password}
onChange={(e) => setPassword(e.target.value)}
disabled={registerMutation.isPending}
required
/>
<p className="text-xs text-muted-foreground">
Minimum 6 caractères
</p>
</div>
<div className="space-y-2">
<Label htmlFor="confirmPassword">Confirmer le mot de passe *</Label>
<Input
id="confirmPassword"
type="password"
placeholder="••••••••"
value={confirmPassword}
onChange={(e) => setConfirmPassword(e.target.value)}
disabled={registerMutation.isPending}
required
/>
</div>
</CardContent>
<CardFooter className="flex flex-col space-y-4">
<Button
type="submit"
className="w-full"
disabled={registerMutation.isPending}
>
{registerMutation.isPending && (
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
)}
S'inscrire
</Button>
<div className="text-sm text-center text-muted-foreground">
Déjà un compte ?{" "}
<button
type="button"
onClick={() => setLocation("/login")}
className="text-primary hover:underline font-medium"
>
Se connecter
</button>
</div>
</CardFooter>
</form>
</Card>
</div>
);
}