"use client"; // Allow or deny a site's request. The provider's client plugin sends the page's signed request (oauth_query) along, // and answers with where to go next: back to the site, with a code or with access_denied. import { oauthProviderClient } from "@better-auth/oauth-provider/client"; import { createAuthClient } from "better-auth/react"; import { useState } from "react"; import { ErrorText } from "@/components/forms"; import { Button } from "@/components/ui/button"; const consentClient = createAuthClient({ baseURL: typeof window === "undefined" ? undefined : window.location.origin, plugins: [oauthProviderClient()], }); export function ConsentForm() { const [pending, setPending] = useState<"allow" | "deny" | null>(null); const [error, setError] = useState(""); async function answer(accept: boolean) { setPending(accept ? "allow" : "deny"); setError(""); const { data, error } = await consentClient.oauth2.consent({ accept }); const url = data && typeof data === "object" && "url" in data ? (data as { url?: string }).url : undefined; if (error || !url) { setError(error?.message ?? "That didn't work. Start again from the site."); setPending(null); return; } window.location.assign(url); } return (