Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Backend: take a user's name from SSO once; later sign-ins keep the stored name (#2914)

0xken156b29b8e5da7b
diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma
index 464447093..efd6f3a14 100644
--- a/backend/prisma/schema.prisma
+++ b/backend/prisma/schema.prisma
@@ -152,7 +152,7 @@ model User {
externalId String @unique // production SSO subject == SDS `customer_id`; local-prod-* until known
stagExternalId String? // staging SSO subject; authentication still keys by email
passwordHash String? // legacy only; SSO users have none
- name String?
+ name String? // from SSO once, while empty; later sign-ins never overwrite it (UserService.upsertFromSso)
role String @default("user") // user | admin
// Which Autonomous account plane this user signs in against. Existing rows are backfilled to
// staging because they were created while the app used staging globally; new users default prod.
diff --git a/backend/src/services/UserService.test.ts b/backend/src/services/UserService.test.ts
index beb151b4a..cadea6189 100644
--- a/backend/src/services/UserService.test.ts
+++ b/backend/src/services/UserService.test.ts
@@ -194,17 +194,31 @@ describe('sign-in attribution', () => {
})
it('never gives an existing account an acquisition from a later tagged sign-in', async () => {
- findUnique.mockResolvedValue(row())
+ findUnique.mockResolvedValue(row({ name: null }))
await userService.upsertFromSso({
externalId: 'prod-sub-1',
autonomousEnv: 'prod',
- name: 'Renamed',
+ name: 'Named',
signUpAttribution: tags,
})
- expect(update).toHaveBeenCalledWith({ where: { id: 'u1' }, data: { name: 'Renamed' } })
+ expect(update).toHaveBeenCalledWith({ where: { id: 'u1' }, data: { name: 'Named' } })
+ })
+
+ it('takes the SSO name once: a later sign-in with another name leaves the stored one', async () => {
+ findUnique.mockResolvedValue(row({ name: 'Elvis' }))
+
+ const user = await userService.upsertFromSso({
+ externalId: 'prod-sub-1',
+ email: '[email protected]',
+ autonomousEnv: 'prod',
+ name: 'Nguyen Phan Thuy',
+ })
+
+ expect(update).not.toHaveBeenCalled()
+ expect(user.name).toBe('Elvis')
})
it('stays off the write path for a current account even when the sign-in is tagged', async () => {
diff --git a/backend/src/services/UserService.ts b/backend/src/services/UserService.ts
index 47af90b14..d81376f05 100644
--- a/backend/src/services/UserService.ts
+++ b/backend/src/services/UserService.ts
@@ -108,7 +108,9 @@ export const userService = {
const data = {
...(claimsProvisional ? signUpAttribution : {}),
...(existing.email !== em ? { email: em } : {}),
- ...(input.name && existing.name !== input.name ? { name: input.name } : {}),
+ // The name is taken from SSO once, while the account has none: later sign-ins never change it, so a name set
+ // in Harness (or by an admin) stays (Ken, 2026-11-04).
+ ...(input.name && !existing.name ? { name: input.name } : {}),
...(existing.role !== role ? { role } : {}),
// A new production subject on this row makes its stored Google subject (lib/googleSubject.ts)
// somebody else's answer: forget it, so the account is unchecked until a live read of THIS