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