File
Blob: src/client/lib/social.ts
| 1 | // Body shape for tessera's social sign-in wrapper at POST /api/sign-in/social. |
| 2 | // Factored out of sign-in.tsx so the `oauth_query` forwarding logic can be |
| 3 | // unit-tested without DOM. |
| 4 | // |
| 5 | // `oauth_query` is the signed query string from /authorize (sig + exp |
| 6 | // included). The wrapper attaches it to Better Auth's `additionalData` so |
| 7 | // oauth-provider's before-hook captures it into oAuthState and the user |
| 8 | // resumes the signed RP flow after the IdP round-trip. |
| 9 | |
| 10 | export type SocialProvider = "github" | "google"; |
| 11 | |
| 12 | export interface SocialSignInRequest { |
| 13 | provider: SocialProvider; |
| 14 | callbackURL: string; |
| 15 | errorCallbackURL: string; |
| 16 | turnstileToken: string; |
| 17 | oauth_query?: string; |
| 18 | } |
| 19 | |
| 20 | export const buildSocialSignInRequest = (input: { |
| 21 | provider: SocialProvider; |
| 22 | callbackURL: string; |
| 23 | errorCallbackURL: string; |
| 24 | turnstileToken: string; |
| 25 | oauthQuery: string | null; |
| 26 | }): SocialSignInRequest => { |
| 27 | const body: SocialSignInRequest = { |
| 28 | provider: input.provider, |
| 29 | callbackURL: input.callbackURL, |
| 30 | errorCallbackURL: input.errorCallbackURL, |
| 31 | turnstileToken: input.turnstileToken, |
| 32 | }; |
| 33 | if (input.oauthQuery) { |
| 34 | body.oauth_query = input.oauthQuery; |
| 35 | } |
| 36 | return body; |
| 37 | }; |