import type { LoadInput } from "@sveltejs/kit" ; import type { ClientRequestConfig } from "./types" ; interface SignInConfig extends ClientRequestConfig { redirectUrl ? : string ; } export async function signIn ( provider , data ? , config ? ) { if ( data ) { const path = mergePath ( [ "/api/auth" , config ?. basePath ?? null ] , `/callback/${ provider }` ) ; const res = await fetch ( path , { method : "POST" , headers : { "Content-Type" : "application/json" , } , body : JSON . stringify ( data ) , } ) ; return await res . json ( ) ; } let redirectUrl ; if ( config ?. redirectUrl ) { redirectUrl = config . redirectUrl ; } else { let $val ; if ( $val ) { redirectUrl = `${ $val . url . host }${ $val . url . pathname }?${ $val . url . searchParams }` ; } } const queryData = { redirect : redirectUrl ?? "/" , } ; const query = new URLSearchParams ( queryData ) ; const path = mergePath ( [ "/api/auth" , config ?. basePath ?? null ] , `/signin/${ provider }?${ query }` ) ; return path ; }