export type GetApiThirdpartyAuthArgs = {provider: 'google' | 'github', redirect_to: unknown}; export type GetApiThirdpartyAuthOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Initialize third party login * * GET /thirdparty/auth */ export const getApiThirdpartyAuth = async (args: GetApiThirdpartyAuthArgs, options?: GetApiThirdpartyAuthOptions) => { const {baseUrl = "https://.hanko.io/admin", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.provider != null) query.append("provider", String(args.provider)) if (args.redirect_to != null) query.append("redirect_to", String(args.redirect_to)) const url = `${baseUrl.replace(/\/+$/, '')}/thirdparty/auth${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 };