RJBULK-APP/actions/profile.ts
SJCoetz 1efa979443 feat: initial setup of rj bulk supplies backoffice app
Adds complete initial codebase for the RJ Bulk Supplies fuel delivery backoffice:
- Authentication pages and protected route layouts
- Customer, supplier, fuel purchase, and delivery note management
- Custom reporting and customer statement sending tools
- Full UI component library and Tailwind styling
- Server actions, API routes, and PocketBase integration
- Development scripts and project configuration updates
- Updated README and package metadata
2026-07-19 20:38:16 +02:00

31 lines
1 KiB
TypeScript

"use server";
import { revalidatePath } from "next/cache";
import { z } from "zod";
import { pbUpdate } from "@/lib/pocketbase";
import { getAuth } from "@/lib/auth";
export type ActionResult = { ok: true } | { ok: false; error: string };
const profileSchema = z.object({
name: z.string().min(1, "Name is required"),
email: z.string().email("Valid email required"),
});
export async function updateProfile(_: unknown, formData: FormData): Promise<ActionResult> {
const { token, user } = await getAuth();
if (!token || !user) return { ok: false, error: "Not signed in" };
const parsed = profileSchema.safeParse({
name: formData.get("name"),
email: formData.get("email"),
});
if (!parsed.success) return { ok: false, error: parsed.error.issues[0]?.message ?? "Invalid input" };
try {
await pbUpdate("users", user.id, parsed.data, token);
} catch (err: any) {
return { ok: false, error: err?.message || "Failed to update" };
}
revalidatePath("/profile");
revalidatePath("/dashboard");
return { ok: true };
}