Phase6c: Optional Company contact name
All checks were successful
Build and Push / build (push) Successful in 1m40s

This commit is contained in:
2026-05-25 13:50:16 +02:00
parent 002867850d
commit a1769eeb00
10 changed files with 530 additions and 7 deletions

View File

@@ -49,7 +49,26 @@ export const authConfig: NextAuthConfig = {
},
],
callbacks: {
async jwt({ token, account, profile }) {
async jwt({ token, account, profile, trigger, session }) {
// Phase 6 fix5: client-side `useSession().update({ name })` calls
// route through this branch. We trust the new value because the
// PUT /api/settings/profile route already wrote it to ZITADEL
// and re-fetched the canonical displayName before returning.
// NextAuth maps token.name → session.user.name on the next
// session callback, so downstream useSession() consumers see
// the new name without a logout/login cycle.
//
// Defensive: only the `name` field is accepted from the update
// payload, even if the client passes additional keys. Other
// identity claims (orgId, roles, sub) come from ZITADEL at
// sign-in time and are not user-mutable from a settings page.
if (trigger === "update" && session) {
const update = session as { name?: unknown };
if (typeof update.name === "string") {
(token as { name?: string }).name = update.name;
}
return token;
}
if (account && profile) {
const claims = profile as unknown as ZitadelClaims;
token.orgId = claims["urn:zitadel:iam:user:resourceowner:id"];