( account: Account, user: NextUser | AdapterUser, _profile: Profile | undefined )
| 272 | assert(user.email, 'User email is required for OpenAI auth'); |
| 273 | |
| 274 | const sub = (profile as { sub?: unknown } | undefined)?.sub; |
| 275 | if (typeof sub !== 'string' || sub.trim() === '') { |
| 276 | throw new Error('OpenAI auth profile is missing the subject'); |
| 277 | } |
| 278 | |
| 279 | return { |
| 280 | google_user_email: user.email, |
| 281 | google_user_name: user.name || user.email.split('@')[0], |
| 282 | google_user_image_url: user.image || '', |
| 283 | hosted_domain: hosted_domain_specials.openai, |
| 284 | provider: account.provider, |
| 285 | // Issuer-qualified subject: a `sub` from any other issuer or client can |
| 286 | // never collide with an OpenAI account. |
| 287 | provider_account_id: `${OPENAI_ISSUER}#${sub}`, |
| 288 | display_name: null, |
| 289 | }; |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * Persists the delegated tokens a completed ChatGPT authorization issued, so |
| 294 | * the same consent that signs a person in also connects OpenAI BYOK. Only a |
| 295 | * grant that carries the delegated scopes is stored: a plain identity-only |
no test coverage detected