@agg-build/auth

中文文档
4.29.0发布于 2026/10/23MITTypeScriptESM + CJS近 30 天下载 1908

Modular connect/sign-in UI and auth-method adapters (SIWE, SIWS, Google, Apple, Twitter/X, email magic-link) for the AGG prediction market aggregator.

原始使用文档
文档目录16 节
  1. What it is
  2. When to use this package
  3. Install
  4. Quick start
  5. Dedicated callback route
  6. Turnstile challenges
  7. Available auth methods
  8. Custom redirect URL / navigation
  9. Custom wallet picker (SIWE)
  10. ConnectButton props
  11. Main exports
  12. Architecture
  13. Entrypoints
  14. Peer dependencies
  15. Links
  16. License

@agg-build/auth

Modular connect / sign-in UI and auth-method adapters for the AGG prediction market aggregator. Drop in a ConnectButton, pick the auth methods you want to enable (SIWE, SIWS, Google, Apple, Twitter/X, email magic-link), and ship.

What it is

@agg-build/auth keeps provider-specific auth integrations out of @agg-build/ui. Each auth method ships as a separate adapter — wallet providers (SIWE, SIWS) stay behind subpath imports so their peer dependencies are only pulled in when you actually enable them. AggAuthProvider orchestrates the flow end-to-end: opening the chooser, driving wallet sign-in, redirecting to OAuth providers, emailing magic links, handling the post-redirect code exchange, and transparently solving Cloudflare Turnstile challenges when the API requires them.

When to use this package

  • You want AGG's connect / sign-in UX without rebuilding it.
  • You want to enable only the auth methods your app supports.
  • You want redirect callback handling (OAuth + email magic-link) solved for you.
  • You want Cloudflare Turnstile challenge handling built in.

If you prefer to roll your own wallet UI, skip this package and use useAggAuth from @agg-build/hooks directly.

Install

Core packages:

npm install @agg-build/sdk @agg-build/hooks @agg-build/ui @agg-build/auth liveline

Add only the optional peers you need:

# SIWE / Ethereum
npm install wagmi viem

# SIWS / Solana
npm install @solana/wallet-adapter-react bs58

Google, Apple, Twitter/X, and email magic-link flows don't require any extra peers — they are plain redirect-based flows driven by the SDK.

Quick start

import "@agg-build/ui/styles.css";
import { QueryClient, QueryClientProvider } from "@agg-build/hooks";
import { createAggClient } from "@agg-build/sdk";
import { AggProvider } from "@agg-build/ui";
import {
  AggAuthProvider,
  ConnectButton,
  createAppleAuthMethod,
  createEmailAuthMethod,
  createGoogleAuthMethod,
  createTwitterAuthMethod,
} from "@agg-build/auth";
import { useSiweAuthMethod } from "@agg-build/auth/siwe";
import { useSiwsAuthMethod } from "@agg-build/auth/siws";
import { WagmiProvider } from "wagmi";
import { wagmiConfig } from "./wagmi-config";

const client = createAggClient({
  appId: "your-app-id",
  baseUrl: "https://api.agg.market",
});
const queryClient = new QueryClient();

function AuthActions() {
  const siwe = useSiweAuthMethod({ statement: "Sign in to AGG" });
  const siws = useSiwsAuthMethod({ cluster: "mainnet", statement: "Sign in to AGG" });

  return (
    <AggAuthProvider
      methods={[
        siwe,
        siws,
        createGoogleAuthMethod(),
        createAppleAuthMethod(),
        createTwitterAuthMethod(),
        createEmailAuthMethod(),
      ]}
    >
      <ConnectButton />
    </AggAuthProvider>
  );
}

export default function App() {
  return (
    <WagmiProvider config={wagmiConfig}>
      <QueryClientProvider client={queryClient}>
        <AggProvider client={client}>
          <AuthActions />
        </AggProvider>
      </QueryClientProvider>
    </WagmiProvider>
  );
}

AggAuthProvider watches the current URL on mount. For redirect-based methods it reads the code query parameter, calls client.exchangeAuthCode(code), then cleans the URL. No extra setup required if the user lands back on the same app.

Dedicated callback route

If your app routes redirects to a separate callback page, hydrate the exchange yourself with useAggAuthCallback:

import { useAggAuthCallback } from "@agg-build/auth";

export function AuthCallbackPage() {
  const { error, isHandled, isHandling, user } = useAggAuthCallback();

  if (isHandling) return <p>Finishing sign-in…</p>;
  if (error) return <p>{error.message}</p>;
  if (isHandled) return <p>Signed in as {user?.id}</p>;

  return <p>No AGG auth callback data was found.</p>;
}

The callback hook follows the same recipe:

  1. Parse the code query parameter.
  2. Call client.exchangeAuthCode(code).
  3. Remove code from the URL via window.history.replaceState(...).

Turnstile challenges

When the AGG API returns challenge_required, AggAuthProvider automatically renders a Cloudflare Turnstile widget, submits the solved token, and retries the request. The widget is invisible on success and degrades gracefully if a user's environment blocks Turnstile. You do not need to render or configure the widget directly.

Available auth methods

Import pathExportPeer depsNotes
@agg-build/authcreateEmailAuthMethod()—Magic-link email flow
@agg-build/authcreateGoogleAuthMethod()—Redirect-based OAuth
@agg-build/authcreateAppleAuthMethod()—Redirect-based OAuth
@agg-build/authcreateTwitterAuthMethod()—Redirect-based OAuth
@agg-build/auth/siweuseSiweAuthMethod()wagmiEthereum wallet sign-in
@agg-build/auth/siwsuseSiwsAuthMethod()@solana/wallet-adapter-react, bs58Solana wallet sign-in; Ledger-compatible

Pass the methods you want to enable to AggAuthProvider — the ConnectButton chooser only lists methods you include.

Custom redirect URL / navigation

Redirect-based adapters accept a redirectUrl and optional navigate function:

createGoogleAuthMethod({
  redirectUrl: "https://yourapp.com/auth/callback",
  navigate: (url) => window.top?.location.assign(url),
});

Custom wallet picker (SIWE)

useSiweAuthMethod accepts an optional connectorPicker to render your own wallet chooser modal instead of wagmi's default:

const siwe = useSiweAuthMethod({
  connectorPicker: async (connectors) => showMyWalletModal(connectors),
});

ConnectButton props

PropTypeDescription
buttonPropsConnectButtonButtonPropsProps passed to the inner Button component
classNamesConnectButtonClassNamesStyle overrides for sub-elements
disabledbooleanDisable the button
onAuthMethodSelect(methodId: AuthMethodId) => void | Promise<void>Called when user picks an auth method
onDepositClick() => void | Promise<void>Called when user clicks deposit
onDisconnect() => void | Promise<void>Called on disconnect
onProfileClick() => void | Promise<void>Called when user clicks profile
onWithdrawClick() => void | Promise<void>Called when user clicks withdraw

When authenticated, the button collapses into the user's profile chip with action buttons (deposit, withdraw, profile, disconnect). Use the callback props to wire them to your app's navigation or modal system.

Main exports

Import pathExportDescription
@agg-build/authAggAuthProviderOrchestrates the chooser, redirect callback, and Turnstile
@agg-build/authConnectButtonDrop-in connect / account chip
@agg-build/authuseAggAuthFlowAccess the chooser/flow state (used by custom UIs)
@agg-build/authuseAggAuthCallbackManually hydrate the redirect callback page
@agg-build/authcreateEmailAuthMethodMagic-link email adapter
@agg-build/authcreateGoogleAuthMethodGoogle OAuth adapter
@agg-build/authcreateAppleAuthMethodApple OAuth adapter
@agg-build/authcreateTwitterAuthMethodTwitter/X OAuth adapter
@agg-build/auth/siweuseSiweAuthMethodSIWE adapter (requires wagmi)
@agg-build/auth/siwsuseSiwsAuthMethodSIWS adapter (requires @solana/wallet-adapter-react + bs58)

Architecture

  • @agg-build/sdk owns auth API calls and session-token storage.
  • @agg-build/hooks owns shared auth/session state inside AggProvider.
  • @agg-build/ui ships generic UI primitives only.
  • @agg-build/auth ships auth-method adapters + the connect/sign-in UX.

Entrypoints

EntryPurpose
@agg-build/authAggAuthProvider, ConnectButton, OAuth + email adapters
@agg-build/auth/connect-buttonConnectButton component only (narrow import)
@agg-build/auth/oauthcreateAppleAuthMethod, createGoogleAuthMethod, createTwitterAuthMethod
@agg-build/auth/emailcreateEmailAuthMethod
@agg-build/auth/siweuseSiweAuthMethod (requires wagmi)
@agg-build/auth/siwsuseSiwsAuthMethod (requires Solana wallet adapter)

Peer dependencies

Required:

  • @agg-build/hooks
  • @agg-build/ui
  • react ^18.0.0 or ^19.0.0
  • react-dom ^18.0.0 or ^19.0.0

Optional (tied to specific adapters):

  • wagmi ^3.5.0 — SIWE
  • @solana/wallet-adapter-react ^0.15.39 — SIWS
  • bs58 ^6.0.0 — SIWS signature encoding

License

MIT

版本与发布记录

@agg-build/auth 共发布 13 个版本,首次发布于 2026/04/28;过去 12 个月发布了 13 个版本。

版本发布日期距今
4.29.0latest2026/10/2316 天前
4.28.02026/10/1722 天前
4.27.02026/10/1425 天前
4.17.22026/09/211 个月前
4.0.02026/08/172 个月前
3.0.02026/08/122 个月前

关于 @agg-build/auth 的常见问题

@agg-build/auth 是什么?

Modular connect/sign-in UI and auth-method adapters (SIWE, SIWS, Google, Apple, Twitter/X, email magic-link) for the AGG prediction market aggregator.

如何安装 @agg-build/auth?

在项目目录运行 npm install @agg-build/auth,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^18.0.0 || ^19.0.0)、react-dom(^18.0.0 || ^19.0.0)、@agg-build/ui(^4.29.0)、@agg-build/hooks(^4.29.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@agg-build/auth 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@agg-build/auth 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@agg-build/auth 可以商用吗?

@agg-build/auth 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@agg-build/auth 的下载量有多少?

根据 npm 官方下载统计,@agg-build/auth 在 2026/10/05 – 2026/11/03 这 30 天内被下载 1,908 次,日均约 64 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@agg-build/auth 还在维护吗?

最新版本 4.29.0 发布于 2026/10/23(16 天前);至今共发布 13 个版本,其中过去 12 个月发布了 13 个;首次发布于 2026/04/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。