feat: setup wizard + settings
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
dd6b880f49
commit
1c3f222f9d
+16
-2
@@ -1,8 +1,9 @@
|
||||
"use server";
|
||||
import { redirect } from "next/navigation";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { userByEmail, getSettings, renameAnalysis, deleteAnalysis } from "@/lib/db";
|
||||
import { signUpNewUser, verifyPassword, startSession, endSession, requireUser, emailOk } from "@/lib/auth";
|
||||
import { userByEmail, getSettings, renameAnalysis, deleteAnalysis, db } from "@/lib/db";
|
||||
import { signUpNewUser, verifyPassword, startSession, endSession, requireUser, emailOk, hashPassword } from "@/lib/auth";
|
||||
import { saveSettingsForm } from "@/lib/settings";
|
||||
|
||||
export async function signUp(_: unknown, fd: FormData) {
|
||||
const r = signUpNewUser(String(fd.get("email") ?? ""), String(fd.get("password") ?? ""));
|
||||
@@ -32,3 +33,16 @@ export async function remove(_: unknown, fd: FormData) {
|
||||
deleteAnalysis(String(fd.get("id") ?? ""), u.id);
|
||||
revalidatePath("/app");
|
||||
}
|
||||
|
||||
export async function saveSettingsAction(_: unknown, fd: FormData) {
|
||||
const u = await requireUser();
|
||||
const email = String(fd.get("email") ?? "").trim().toLowerCase();
|
||||
const password = String(fd.get("password") ?? "");
|
||||
if (email && !emailOk(email)) return { ok: false, error: "Enter a valid email address." };
|
||||
if (password && password.length < 10) return { ok: false, error: "Use at least 10 characters." };
|
||||
saveSettingsForm(u.id, fd);
|
||||
if (password) db.prepare("UPDATE users SET pass = ? WHERE id = ?").run(hashPassword(password), u.id);
|
||||
if (email) db.prepare("UPDATE users SET email = ? WHERE id = ?").run(email, u.id);
|
||||
revalidatePath("/settings");
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user