This commit is contained in:
Dominik Klarkowski
2026-06-18 11:02:31 +02:00
parent d00a5a42ac
commit 047e580da0
32 changed files with 735 additions and 189 deletions

28
app/settings/actions.ts Normal file
View File

@@ -0,0 +1,28 @@
"use server";
import { revalidatePath } from "next/cache";
import { saveGarminCredentials } from "@/lib/models/garmin-auth";
import { getCurrentUserId } from "@/lib/session";
export type SaveGarminCredentialsState = { error: string } | { success: true } | null;
export async function saveGarminCredentialsAction(
_prevState: SaveGarminCredentialsState,
formData: FormData
): Promise<SaveGarminCredentialsState> {
const email = formData.get("email");
const password = formData.get("password");
if (typeof email !== "string" || !email.includes("@")) {
return { error: "Podaj prawidłowy adres e-mail." };
}
if (typeof password !== "string" || password.length < 1) {
return { error: "Podaj hasło." };
}
const userId = await getCurrentUserId();
await saveGarminCredentials(userId, email.trim(), password);
revalidatePath("/settings");
return { success: true };
}