BigBlocks

OAuth Callback

OAuth callback page block with loading, success, and error states for post-redirect authentication handling

Installation

bunx shadcn@latest add https://registry.bigblocks.dev/r/oauth-callback.json

Usage

Place this block on your OAuth callback page (e.g. app/auth/callback/page.tsx). It reads code, state, and error from the URL search params automatically.

import { OAuthCallback } from "@/components/blocks/oauth-callback"
import { authClient } from "@/lib/auth-client"
 
export default function CallbackPage() {
  return (
    <OAuthCallback
      onCallback={async ({ code, state }) => {
        const result = await authClient.sigma.handleCallback(
          new URLSearchParams({ code, state })
        )
        return {
          user: {
            id: result.user.sub,
            name: result.user.name,
            image: result.user.picture ?? undefined,
            pubkey: result.user.pubkey,
            bapId: result.user.bap_id,
          },
          accessToken: result.access_token,
        }
      }}
      redirectUrl="/dashboard"
      redirectDelay={2000}
      onSuccess={(result) => console.log("Authenticated:", result.user.id)}
      onError={(err) => console.error("Callback failed:", err)}
    />
  )
}

States

The block renders three states based on the callback flow:

StatusRendered UI
loadingSpinner card with skeleton placeholders
successUser avatar, name, public key, and redirect countdown
errorError message with a retry button

Props

OAuthCallback

PropTypeDefaultDescription
onCallback(params: { code: string; state: string }) => Promise<OAuthCallbackResult>Handler to exchange auth code for user data (required)
onSuccess(result: OAuthCallbackResult) => voidCalled after successful callback processing
onError(error: Error) => voidCalled when callback processing fails
redirectUrlstring"/"URL to redirect to after success
redirectDelaynumber2000Delay in ms before redirecting
classNamestringAdditional CSS classes

Hook

useOAuthCallback can be used independently for a fully custom callback page.

import { useOAuthCallback } from "@/components/blocks/oauth-callback"
 
function CustomCallbackPage() {
  const { status, user, errorMessage, retry } = useOAuthCallback({
    onCallback: async ({ code, state }) => {
      const result = await exchangeCode(code, state)
      return { user: { id: result.id, name: result.name } }
    },
    redirectUrl: "/dashboard",
  })
 
  if (status === "loading") return <p>Processing...</p>
  if (status === "error") return <button onClick={retry}>{errorMessage}</button>
  return <p>Welcome, {user?.name}</p>
}