@txwallet/next
v0.1.0
Published
Next.js App Router handlers for Sign in with TX Wallet.
Maintainers
Readme
@txwallet/next
Next.js App Router handlers for Sign in with TX Wallet. The backend is one catch-all route — no Express, no hand-rolled endpoints.
Auth signs an off-chain ADR-36 proof. It does not move funds or authorize checkout.
The ADR-36 verifier is shared with @txwallet/auth-express — one
verifier for the whole toolkit.
Install
npm install @txwallet/nextBackend — one file
app/api/tx-wallet/[...txwallet]/route.js
import { createTxWalletAuthHandlers } from '@txwallet/next';
// ADR-36 verification uses Node crypto — keep this route on the Node runtime.
export const runtime = 'nodejs';
const handlers = createTxWalletAuthHandlers({
appId: process.env.TX_WALLET_APP_ID,
appDomain: process.env.TX_WALLET_APP_DOMAIN,
allowedOrigins: ['https://example.com'],
allowedCallbackPaths: ['/tx-wallet/callback'],
allowedChainIds: ['coreum-mainnet-1'],
async createSessionForAccount({ account }) {
// account.address is proven. Set your session, e.g. with next/headers:
// (await cookies()).set('session', await mintSession(account.address));
},
});
export const GET = handlers.GET;
export const POST = handlers.POST;This serves the four Auth endpoints under /api/tx-wallet/signin/requests.
Frontend
Use @txwallet/react — point its endpoint at the route above:
<TxWalletProvider config={{ requestOptions: {
endpoint: '/api/tx-wallet/signin/requests',
callbackUrl: `${location.origin}/tx-wallet/callback`,
} }}>
<TxWalletSignInButton />
</TxWalletProvider>Notes
- Runtime: must be
'nodejs'(the verifier uses Node crypto /@cosmjs), not Edge. - Store: request state is in-memory by default — fine for a single instance. For
multi-instance deploys pass a shared
store(anyMap-compatible object backed by your KV/Redis). - The backend remains the source of truth — confirm the session server-side after approval.
