export type GetApiAuthProviderCallbackArgs = {provider: 'google' | 'facebook' | 'apple'}; export type GetApiAuthProviderCallbackOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; /** * Redirect endpoint after performing oauth flow with facebook, google, apple. * * GET /auth/{provider}/callback * * Also accepts auth: API-Key */ export const getApiAuthProviderCallback = async (args: GetApiAuthProviderCallbackArgs, options: GetApiAuthProviderCallbackOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/auth/${encodeURIComponent(String(args.provider))}/callback${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };