( session: VerifiedSession, cookieHeader: string | null, )
| 110 | * fields (which would ping-pong with the client's authoritative write). |
| 111 | */ |
| 112 | const resolveAuthHint = async ( |
| 113 | session: VerifiedSession, |
| 114 | cookieHeader: string | null, |
| 115 | ): Promise<{ hint: AuthHint; mint: boolean }> => { |
| 116 | const existing = decodeAuthHint(parseCookie(cookieHeader, AUTH_HINT_COOKIE)); |
| 117 | if ( |
| 118 | existing && |
| 119 | existing.user.id === session.userId && |
| 120 | (existing.organization?.id ?? null) === session.organizationId |
| 121 | ) { |
| 122 | return { hint: existing, mint: false }; |
| 123 | } |
| 124 | return { |
| 125 | hint: { |
| 126 | v: 1, |
| 127 | user: { |
| 128 | id: session.userId, |
| 129 | email: session.email, |
| 130 | name: session.name, |
| 131 | avatarUrl: session.avatarUrl, |
| 132 | }, |
| 133 | organization: session.organizationId |
| 134 | ? { |
| 135 | id: session.organizationId, |
| 136 | ...(await organizationDisplay(session.organizationId)), |
| 137 | } |
| 138 | : null, |
| 139 | }, |
| 140 | mint: true, |
| 141 | }; |
| 142 | }; |
| 143 | |
| 144 | // The sealed session carries the org ID but not its name/slug; the local |
| 145 | // mirror has both (every org row is born with a slug — see |
no test coverage detected