import { useState } from "react";
import { useSunbreak } from "@tdfc/sunbreak-react";
export function LoginAndAccessGate() {
const { allowed, error } = useSunbreak();
const [loggedIn, setLoggedIn] = useState(false);
async function handleLogin() {
// 1) Your own login + wallet connect
// - e.g. Dynamic, Privy, Wagmi + SIWE, custom JWT, etc.
await connectWalletAndAppAuth();
// 2) Once logged in, do NOTHING Sunbreak-specific.
// The SDK will:
// - detect the wallet + proof
// - auto-run /auth/register (if needed)
// - auto-run /auth/refresh
// - auto-run /api/session
// - populate allowed when ready
setLoggedIn(true);
}
if (!loggedIn) {
return <button onClick={handleLogin}>Sign in</button>;
}
if (error) {
return <p>Something went wrong: {error}</p>;
}
// If blocked
if (allowed === false) {
return <p>Access denied</p>;
}
// If granted
if (allowed === true) {
return <p>Access granted. You may continue.</p>;
}
// While Sunbreak is still evaluating access
return <p>Checking access…</p>;
}