@agg-market/auth
v14.0.0
Published
Composable auth UI and provider adapters for the [AGG](https://agg.market) SDK.
Readme
@agg-market/auth
Composable auth UI and provider adapters for the AGG SDK.
This package keeps provider-specific auth integrations out of @agg-market/ui. Use it when you
want AGG’s connect/sign-in UX with only the auth methods your app actually installs.
Install
Base install:
npm install @agg-market/sdk @agg-market/hooks @agg-market/ui @agg-market/authAdd only the auth peers you need:
# SIWE / Ethereum
npm install wagmi
# SIWS / Solana
npm install @solana/wallet-adapter-react bs58Quick start
import "@agg-market/ui/styles.css";
import { AggProvider } from "@agg-market/hooks";
import { createAggClient } from "@agg-market/sdk";
import {
AggAuthProvider,
ConnectButton,
createAppleAuthMethod,
createEmailAuthMethod,
createGoogleAuthMethod,
} from "@agg-market/auth";
import { useSiweAuthMethod } from "@agg-market/auth/siwe";
import { WagmiProvider } from "wagmi";
import { wagmiConfig } from "./wagmi-config";
const client = createAggClient({
appId: "your-app-id",
baseUrl: "https://api.agg.market",
});
function AuthButton() {
const siwe = useSiweAuthMethod({
statement: "Sign in to AGG",
});
return (
<AggAuthProvider
methods={[siwe, createGoogleAuthMethod(), createAppleAuthMethod(), createEmailAuthMethod()]}
>
<ConnectButton />
</AggAuthProvider>
);
}
export function App() {
return (
<WagmiProvider config={wagmiConfig}>
<AggProvider client={client}>
<AuthButton />
</AggProvider>
</WagmiProvider>
);
}AggAuthProvider automatically checks the current callback URL on mount. For redirect-based auth
providers, it reads the code query parameter, calls client.exchangeAuthCode(code), and then
cleans the callback URL through the shared hooks layer.
Available adapters
| Import path | Export | Notes |
| ----------------------- | --------------------------- | -------------------------------------------------------------------------------------------------------- |
| @agg-market/auth | createAppleAuthMethod() | Redirect-based OAuth |
| @agg-market/auth | createGoogleAuthMethod() | Redirect-based OAuth |
| @agg-market/auth | createTwitterAuthMethod() | Redirect-based OAuth |
| @agg-market/auth | createEmailAuthMethod() | Magic-link email flow |
| @agg-market/auth/siwe | useSiweAuthMethod() | Requires wagmi |
| @agg-market/auth/siws | useSiwsAuthMethod() | Requires @solana/wallet-adapter-react + bs58; signs raw UTF-8 bytes and base58-encodes the signature |
Redirect callback routes
If your app uses a dedicated callback page, you can hydrate the redirect callback explicitly:
import { useAggAuthCallback } from "@agg-market/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>;
}This uses the documented redirect recipe:
- parse the
codequery parameter from the callback URL - call
client.exchangeAuthCode(code) - remove
codefrom the URL viawindow.history.replaceState(...)
Migration from @agg-market/ui
Older versions exposed an auth-centric ConnectButton from @agg-market/ui. That coupling has
been removed.
- Keep
AggProviderfrom@agg-market/hooks - Add
AggAuthProviderfrom@agg-market/auth - Move
ConnectButtonimports to@agg-market/auth - Install only the provider peers your enabled methods need:
wagmifor SIWE@solana/wallet-adapter-reactandbs58for SIWS- no wallet packages for Google, Apple, Twitter, or email
Architecture
@agg-market/sdkowns auth API calls and session token storage.@agg-market/hooksowns shared auth/session state insideAggProvider.@agg-market/uistays generic and ships reusable UI primitives only.@agg-market/authowns auth method adapters plus the connect/sign-in UX.
License
MIT
