Initial commit: WaMarket MVP
Marketplace inversée (Next.js 16 App Router + Supabase Cloud) : auth, schéma + RLS, publication de besoins avec upload d'images, feed avec filtres, offres, acceptation via RPC, messagerie temps réel, dashboards, et Dockerfile pour déploiement Coolify.
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
"use server";
|
||||
|
||||
import { redirect } from "next/navigation";
|
||||
import { createClient } from "@/lib/supabase/server";
|
||||
import {
|
||||
LoginFormSchema,
|
||||
SignupFormSchema,
|
||||
type FormState,
|
||||
} from "@/lib/validations/auth";
|
||||
|
||||
export async function signup(
|
||||
_state: FormState,
|
||||
formData: FormData
|
||||
): Promise<FormState> {
|
||||
const validatedFields = SignupFormSchema.safeParse({
|
||||
fullName: formData.get("fullName"),
|
||||
email: formData.get("email"),
|
||||
password: formData.get("password"),
|
||||
});
|
||||
|
||||
if (!validatedFields.success) {
|
||||
return { errors: validatedFields.error.flatten().fieldErrors };
|
||||
}
|
||||
|
||||
const { fullName, email, password } = validatedFields.data;
|
||||
const supabase = await createClient();
|
||||
|
||||
const { error } = await supabase.auth.signUp({
|
||||
email,
|
||||
password,
|
||||
options: { data: { full_name: fullName } },
|
||||
});
|
||||
|
||||
if (error) {
|
||||
return { message: error.message };
|
||||
}
|
||||
|
||||
redirect("/dashboard/my-needs");
|
||||
}
|
||||
|
||||
export async function login(
|
||||
_state: FormState,
|
||||
formData: FormData
|
||||
): Promise<FormState> {
|
||||
const validatedFields = LoginFormSchema.safeParse({
|
||||
email: formData.get("email"),
|
||||
password: formData.get("password"),
|
||||
});
|
||||
|
||||
if (!validatedFields.success) {
|
||||
return { errors: validatedFields.error.flatten().fieldErrors };
|
||||
}
|
||||
|
||||
const { email, password } = validatedFields.data;
|
||||
const supabase = await createClient();
|
||||
|
||||
const { error } = await supabase.auth.signInWithPassword({
|
||||
email,
|
||||
password,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
return { message: "Email ou mot de passe incorrect." };
|
||||
}
|
||||
|
||||
redirect("/dashboard/my-needs");
|
||||
}
|
||||
|
||||
export async function logout() {
|
||||
const supabase = await createClient();
|
||||
await supabase.auth.signOut();
|
||||
redirect("/auth/login");
|
||||
}
|
||||
Reference in New Issue
Block a user