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:
+28
@@ -165,6 +165,34 @@ export const { handlers, auth, signIn, signOut } = NextAuth({
|
||||
token.ver = user.tokenVersion
|
||||
token.role = user.role
|
||||
}
|
||||
if (trigger === 'update' && typeof token.id === 'string' && typeof token.ver === 'number') {
|
||||
// Profile edits (Settings → Profile) call useSession().update({})
|
||||
// so the session identity re-syncs from Go — the top bar and
|
||||
// profile header reflect a new name without a re-login. (A bare
|
||||
// update() only re-fetches; the data argument is what fires this
|
||||
// trigger in next-auth v5.) Same assertion the data proxy signs;
|
||||
// fail-quiet keeps the old values when Go is unreachable (the save
|
||||
// itself already succeeded or failed loudly).
|
||||
const secret = process.env.NEXTAUTH_SECRET || process.env.AUTH_SECRET
|
||||
if (secret) {
|
||||
try {
|
||||
const assertion = jwt.sign({ uid: token.id, ver: token.ver, typ: 'assertion' }, secret, { algorithm: 'HS256', issuer: 'superbrain', expiresIn: '60s' })
|
||||
const response = await fetch(`${process.env.API_BASE_URL || 'http://localhost:8080'}/api/me`, {
|
||||
headers: { Authorization: `Bearer ${assertion}` },
|
||||
cache: 'no-store',
|
||||
signal: AbortSignal.timeout(5000),
|
||||
})
|
||||
if (response.ok) {
|
||||
const u = (await response.json())?.user
|
||||
if (u) {
|
||||
token.name = u.name ?? null
|
||||
token.email = u.email ?? null
|
||||
token.picture = u.image ?? null
|
||||
}
|
||||
}
|
||||
} catch { /* keep the previous identity */ }
|
||||
}
|
||||
}
|
||||
return token
|
||||
},
|
||||
async session({ session, token }) {
|
||||
|
||||
Reference in New Issue
Block a user