'use client'; //=========================================== // THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY UNLESS YOU ALSO EDIT THE CORRESPONDING FILE IN packages/template //=========================================== import { KnownError } from "@hexclave/shared"; import { captureError } from "@hexclave/shared/dist/utils/errors"; import { runAsynchronously } from "@hexclave/shared/dist/utils/promises"; import { Spinner, cn } from "@hexclave/ui"; import { useEffect, useRef, useState } from "react"; import { useStackApp } from ".."; import { MaybeFullPage } from "../components/elements/maybe-full-page"; import { hexclaveAppInternalsSymbol } from "../lib/hexclave-app/common"; import { ErrorPage } from "./error-page"; export function OAuthCallback({ fullPage }: { fullPage?: boolean }) { const app = useStackApp(); const called = useRef(false); const [errorSearchParams, setErrorSearchParams] = useState | null>(null); useEffect(() => runAsynchronously(async () => { if (called.current) return; called.current = true; try { // The startup handler in StackClientApp's constructor may have already consumed the // one-time OAuth params (code + state cookie) via a microtask that fires before this // macrotask-scheduled useEffect. Await its completion so we don't race: if it succeeds // it will redirect and this page tears down; if it fails we fall through below. await app[hexclaveAppInternalsSymbol].awaitPendingAuthResolutions(); const hasRedirected = await app.callOAuthCallback(); if (!hasRedirected) { await app.redirectToSignIn({ noRedirectBack: true }); } } catch (e) { if (KnownError.isKnownError(e)) { setErrorSearchParams({ errorCode: e.errorCode, message: e.message, details: JSON.stringify(e.details ?? {}), }); return; } captureError("", e); setErrorSearchParams({}); } }), [app]); if (errorSearchParams != null) { return ; } return (
); }