Settings → Profile: editable particulars (name, bio, location, occupation, organization, website)
The Profile tab was a read-only avatar/name/email stub. It is now a real
form, modeled on the profile surfaces of GitHub/Slack/Nextcloud and scoped
to what a knowledge tool uses: display name, bio (280 chars with counter),
location, occupation, organization and website; email stays read-only
(sign-in identity). Copy explains where the name appears (shares) and
that public bookmark links never reveal identity.
Schema: migration 024_user_profile.sql + schema.sql add five nullable
text columns to User (db-converge green, fresh and upgraded paths).
models.User, userFromObject and the auth identity projection carry them,
so GET /api/me serves the stored truth (Go re-reads identity per request).
PATCH /api/me applies partial allowlisted edits: empty string clears to
NULL, rune-based caps (120/280/120/120/120), website <=2048 and http(s)
with a host; the answer is the fresh identity projection. User has no
version column (identity, not a collaborative collection), so this follows
the settings-save shape rather than the 409 contract; view-as writes stay
blocked by the middleware.
Session propagation: the auth.ts jwt callback gains an "update" trigger
that re-syncs name/email/image from Go via the same assertion the data
proxy signs (fail-quiet when Go is unreachable). The component calls
useSession().update({}) after a save — the {} argument is load-bearing:
in next-auth v5 a bare update() only re-fetches the session, it does not
fire the trigger (caught by the new browser regression). The top bar name
refreshes without a re-login.
Verified: full Go integration suite green incl. new TestProfileUpdate
(partial edits, clearing, rune caps, URL validation, auth gate);
db-converge green; web lint/SSR-lint/build 0 errors; full browser
regressions pass incl. the new profile round-trip (save → toast → top-bar
refresh → form values intact → Save re-disables on a clean baseline).
This commit is contained in:
+48
-2
@@ -70,6 +70,12 @@ const carddavConnections = [{
|
||||
lastSyncedAt: null, lastError: null, version: 1, createdAt: '2026-11-10T00:00:00Z', updatedAt: '2026-11-10T00:00:00Z',
|
||||
}]
|
||||
const carddavSuggestions = [{ kind: 'nextcloud', name: 'Nextcloud contacts', url: 'https://cloud.federatedcomputer.ai/remote.php/dav/addressbooks/users/' }]
|
||||
// The identity is mutable: Settings → Profile PATCHes it, and the NextAuth
|
||||
// jwt "update" trigger re-reads it from /api/me (session name refresh).
|
||||
const fixtureUser = {
|
||||
id: 'fixture-user', name: 'Fixture', email: 'fixture@superbrain.test', role: 'USER', image: null,
|
||||
bio: null, location: null, occupation: null, organization: null, website: null,
|
||||
}
|
||||
const api = http.createServer(async (req, res) => {
|
||||
try {
|
||||
let raw = ''
|
||||
@@ -86,13 +92,24 @@ const api = http.createServer(async (req, res) => {
|
||||
const body = raw ? JSON.parse(raw) : {}
|
||||
const url = new URL(req.url, 'http://fixture')
|
||||
let result = []
|
||||
if (url.pathname === '/api/auth/login') result = { user: { id: 'fixture-user', name: 'Fixture', email: body.email, role: 'USER' }, tokenVersion: 1 }
|
||||
if (url.pathname === '/api/auth/login') result = { user: { ...fixtureUser, email: body.email }, tokenVersion: 1 }
|
||||
else if (url.pathname === '/api/auth/signout' && req.method === 'POST') {
|
||||
signouts.push(req.headers.authorization || '')
|
||||
if (failSignout) { res.writeHead(500, { 'Content-Type': 'application/json' }); res.end('{"error":"Fixture revocation failed"}'); return }
|
||||
result = { ok: true }
|
||||
}
|
||||
else if (url.pathname === '/api/me') result = { user: { id: 'fixture-user' }, effectiveUser: { id: 'fixture-user' }, isAdmin: false, viewingAs: null }
|
||||
else if (url.pathname === '/api/me') {
|
||||
if (req.method === 'PATCH') {
|
||||
// Mirror Go's allowlist + empty-string-clears semantics; the answer
|
||||
// is the flat user projection (same shape as GET /api/me's "user").
|
||||
for (const k of ['name', 'bio', 'location', 'occupation', 'organization', 'website']) {
|
||||
if (k in body) fixtureUser[k] = body[k] === '' ? null : body[k]
|
||||
}
|
||||
result = fixtureUser
|
||||
} else {
|
||||
result = { user: fixtureUser, effectiveUser: { id: fixtureUser.id, name: fixtureUser.name, email: fixtureUser.email, role: fixtureUser.role }, isAdmin: false, viewingAs: null }
|
||||
}
|
||||
}
|
||||
// The list endpoint is a metadata projection: content bodies stay out (PERF-01).
|
||||
else if (url.pathname === '/api/pages') {
|
||||
if (req.method === 'PUT') {
|
||||
@@ -680,6 +697,35 @@ try {
|
||||
await eventually(() => pages.get('a')?.position === 0 && pages.get('b')?.position === 1, 'Sidebar page drag did not reorder')
|
||||
console.log('PASS: sidebar persists drag reordering')
|
||||
|
||||
// Settings → Profile: particulars load from /api/me, the save PATCHes the
|
||||
// allowlist, and the NextAuth session re-syncs from Go (jwt update trigger)
|
||||
// so the top bar shows the new name without a re-login.
|
||||
await page.goto(`${base}/settings`)
|
||||
await page.getByRole('tab', { name: 'Profile' }).click()
|
||||
await page.getByPlaceholder('Your name').waitFor()
|
||||
assert.equal(await page.getByPlaceholder('Your name').inputValue(), 'Fixture')
|
||||
await page.getByPlaceholder('Your name').fill('Fixture Person')
|
||||
await page.getByPlaceholder('A short introduction').fill('Keeper of the second brain')
|
||||
await page.getByPlaceholder('City, country').fill('Berlin, Germany')
|
||||
await page.getByPlaceholder('Job title').fill('Knowledge worker')
|
||||
await page.getByPlaceholder('Company or team').fill('Federated Computer')
|
||||
await page.getByPlaceholder('https://example.com').fill('https://federatedcomputer.ai')
|
||||
await page.getByRole('button', { name: 'Save profile' }).click()
|
||||
await eventually(() => fixtureUser.name === 'Fixture Person' && fixtureUser.website === 'https://federatedcomputer.ai', 'Profile save PATCH did not reach the API')
|
||||
await page.getByText('Profile saved').waitFor()
|
||||
// The save response is the flat projection: the form keeps the values.
|
||||
assert.equal(await page.getByPlaceholder('Your name').inputValue(), 'Fixture Person')
|
||||
assert.equal(await page.getByPlaceholder('https://example.com').inputValue(), 'https://federatedcomputer.ai')
|
||||
assert.equal(fixtureUser.bio, 'Keeper of the second brain')
|
||||
assert.equal(fixtureUser.location, 'Berlin, Germany')
|
||||
assert.equal(fixtureUser.occupation, 'Knowledge worker')
|
||||
assert.equal(fixtureUser.organization, 'Federated Computer')
|
||||
// The top bar (header) reflects the refreshed session identity.
|
||||
await eventually(() => page.locator('header').getByText('Fixture Person', { exact: true }).isVisible(), 'top bar did not refresh the session name after the profile save')
|
||||
// Clean baseline: the save button disables again until the next edit.
|
||||
assert.ok(await page.getByRole('button', { name: 'Save profile' }).isDisabled(), 'Save stayed enabled after a clean save')
|
||||
console.log('PASS: Settings → Profile saves particulars and refreshes the session identity')
|
||||
|
||||
// Settings → WebDAV: masked list rows render; the deployment suggestion
|
||||
// (NEXTCLOUD_URL) prefills the connect form with the username composed into
|
||||
// the per-user DAV root;
|
||||
|
||||
Reference in New Issue
Block a user