mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-12-01 09:24:46 +00:00
feat(pwa): signup profile fields via @profullstack/profile (#256)
The create-account form (/?mode=up) asks for first/last name (required) and company domain, job title, LinkedIn (optional) beside the email box, rendered by renderProfileFields. /auth/register validates them with validateProfile before the user exists and stores them with saveSignupProfile in a new user_profiles table keyed by users.id. GET/PUT/PATCH /api/v1/me/profile (session cookie) and a "Your details" card on /settings. Sign-in, passkey and CoinPay are unchanged. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
ff0c903c6d
commit
50eb8ac30d
10 changed files with 230 additions and 6 deletions
|
|
@ -49,6 +49,13 @@ input:focus,textarea:focus,select:focus{outline:none;border-color:var(--green)}
|
|||
input::placeholder,textarea::placeholder{color:var(--faint)}
|
||||
label.field{display:block;margin-bottom:14px}
|
||||
label.field span{display:block;font-family:var(--mono);font-size:.66rem;letter-spacing:.14em;text-transform:uppercase;color:var(--faint);margin-bottom:6px}
|
||||
/* the signup profile (@profullstack/profile): same look as label.field */
|
||||
.pfs-profile{border:0;padding:0;margin:0;min-width:0}
|
||||
.pfs-profile__row{margin-bottom:14px}
|
||||
.pfs-profile__row label{display:block;font-family:var(--mono);font-size:.66rem;letter-spacing:.14em;text-transform:uppercase;color:var(--faint);margin-bottom:6px}
|
||||
.pfs-profile__optional{text-transform:none;letter-spacing:0}
|
||||
.pfs-profile input[aria-invalid="true"]{border-color:var(--danger)}
|
||||
.pfs-profile__error{margin:6px 0 0;font-size:.78rem;color:var(--danger)}
|
||||
.card{border:1px solid var(--line);border-radius:var(--r);background:var(--surface)}
|
||||
.card-head{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:13px 16px;border-bottom:1px solid var(--line)}
|
||||
.card-head .h{font-family:var(--mono);font-size:.72rem;letter-spacing:.14em;text-transform:uppercase;color:var(--faint)}
|
||||
|
|
|
|||
45
apps/pwa/src/lib/profile.mjs
Normal file
45
apps/pwa/src/lib/profile.mjs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
// The signup profile (@profullstack/profile): email, first/last name, company
|
||||
// domain, job title, LinkedIn URL, in user_profiles keyed by users.id.
|
||||
//
|
||||
// profiles the store, on the app's own client
|
||||
// profileRouter GET/PUT/PATCH /api/v1/me/profile (session cookie)
|
||||
//
|
||||
// The package's handlers speak Web Request/Response; Express has already parsed
|
||||
// the body, so it is handed back to them as JSON.
|
||||
import { Router } from "express";
|
||||
import { createProfileHandlers, createProfileStore } from "@profullstack/profile";
|
||||
import { db } from "../db.mjs";
|
||||
|
||||
export const profiles = createProfileStore(db);
|
||||
|
||||
const handlers = createProfileHandlers({
|
||||
store: profiles,
|
||||
// Only a browser session: this is a person's own details.
|
||||
getUser: (_request, req) => (req.user ? { id: req.user.id, email: req.user.email || null } : null),
|
||||
});
|
||||
|
||||
function toRequest(req) {
|
||||
const hasBody = !["GET", "HEAD"].includes(req.method);
|
||||
return new Request(`http://localhost${req.originalUrl}`, {
|
||||
method: req.method,
|
||||
headers: { "content-type": "application/json", accept: "application/json" },
|
||||
body: hasBody ? JSON.stringify(req.body ?? {}) : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
async function send(res, response) {
|
||||
res.status(response.status);
|
||||
response.headers.forEach((value, key) => res.set(key, value));
|
||||
res.send(Buffer.from(await response.arrayBuffer()));
|
||||
}
|
||||
|
||||
export const profileRouter = Router();
|
||||
for (const method of ["GET", "PUT", "PATCH"]) {
|
||||
profileRouter[method.toLowerCase()]("/api/v1/me/profile", async (req, res, next) => {
|
||||
try {
|
||||
await send(res, await handlers[method](toRequest(req), req));
|
||||
} catch (e) {
|
||||
next(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue