-
- You’re not logged in
-
-
- Please log in to view your account.
-
+
+ You’re not logged in. Please log in to view your account.
);
}
+ const authedUser = user; // user is non-null from here down
- const planLabel = user.role === "ADMIN" ? "Admin" : "Beta Access";
+ async function saveDisplayName() {
+ setSaving(true);
+ setMsg(null);
+
+ try {
+ const nextName = displayName.trim();
+
+ const res = await fetch(`${API_BASE_URL}/api/users/me`, {
+ method: "PATCH",
+ headers: {
+ "Content-Type": "application/json",
+ ...(token ? { Authorization: `Bearer ${token}` } : {}),
+ },
+ body: JSON.stringify({ displayName: nextName }),
+ });
+
+ if (!res.ok) {
+ const text = await res.text().catch(() => "");
+ throw new Error(text || "Failed to update profile");
+ }
+
+ const updated = await res.json().catch(() => null);
+
+ const nextUser = {
+ email: authedUser.email,
+ displayName: updated?.displayName ?? nextName,
+ role: authedUser.role,
+ };
+
+ if (token) setSession(token, nextUser);
+
+ setMsg("Saved ✅");
+ setEditingName(false);
+
+ // If we came from the welcome flow, clear the param
+ if (welcome) router.replace("/account");
+ } catch (e: any) {
+ setMsg(e?.message || "Couldn’t save. Try again.");
+ } finally {
+ setSaving(false);
+ }
+ }
+
+ async function savePassword() {
+ setPwMsg(null);
+
+ if (pw1.length < 8) {
+ setPwMsg("Password must be at least 8 characters.");
+ return;
+ }
+ if (pw1 !== pw2) {
+ setPwMsg("Passwords don’t match.");
+ return;
+ }
+
+ setPwSaving(true);
+
+ try {
+ const res = await fetch(`${API_BASE_URL}/api/users/me/password`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ ...(token ? { Authorization: `Bearer ${token}` } : {}),
+ },
+ body: JSON.stringify({ password: pw1 }),
+ });
+
+ if (!res.ok) {
+ const text = await res.text().catch(() => "");
+ throw new Error(text || "Failed to set password");
+ }
+
+ setPwMsg("Password set ✅ You can now use email + password login.");
+ setPw1("");
+ setPw2("");
+ setShowPassword(false);
+
+ if (welcome) router.replace("/account");
+ } catch (e: any) {
+ setPwMsg(e?.message || "Couldn’t set password. Try again.");
+ } finally {
+ setPwSaving(false);
+ }
+ }
return (
- {/* Quick stats (lightweight “premium” feel) */}
- {/*
-
-
-
-
-
*/}
-
-
-
- Read-only (for now)
-
- }
- >
-
-
|
-
|
-
|
+ {/* Welcome / Setup card (only if needed) */}
+ {showWelcomeCard && (
+
+
+
Welcome to the beta 👋
+
+ Quick setup and you’re ready to cook.
+
-
-
-
-
- Coming soon
-
- }
- >
-
-