export type GetApiThirdpartyCallbackArgs = {code?: string | undefined, state: string, error?: string | undefined, error_description?: string | undefined}; export type GetApiThirdpartyCallbackOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Third party provider callback * * GET /thirdparty/callback */ export const getApiThirdpartyCallback = async (args: GetApiThirdpartyCallbackArgs, options?: GetApiThirdpartyCallbackOptions) => { const {baseUrl = "https://.hanko.io/admin", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.code != null) query.append("code", String(args.code)) if (args.state != null) query.append("state", String(args.state)) if (args.error != null) query.append("error", String(args.error)) if (args.error_description != null) query.append("error_description", String(args.error_description)) const url = `${baseUrl.replace(/\/+$/, '')}/thirdparty/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 };