npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@tuwaio/satellite-siwe-next-auth

v0.2.1

Published

A robust connector module for enabling secure Web3 authentication in Next.js by combining NextAuth with the SIWE standard.

Readme

Satellite SIWE Next.js Auth

NPM Version License Build Status

A robust connector module for enabling secure Web3 authentication (Sign-In with Ethereum, SIWE) in Next.js App Router using Iron Session for state management.


🏛️ What is @tuwaio/satellite-siwe-next-auth?

@tuwaio/satellite-siwe-next-auth provides a secure, boilerplate-free solution for integrating Sign-In with Ethereum (SIWE) authentication into Next.js applications using the App Router.

It replaces the complexity of traditional NextAuth setup by leveraging Iron Session for robust, encrypted, server-side session management, ensuring a seamless and fully decentralized authentication experience.

Built on top of Wagmi/Viem for signature generation.


✨ Key Features

  • Full App Router Support: Provides a single-file API handler designed specifically for the Next.js app/api/[...]/route.ts pattern.
  • No NextAuth Dependency: Uses the lightweight Iron Session for session encryption, eliminating compatibility issues with NextAuth.
  • Auto-Session Management: Handles automatic re-authentication and session cleanup upon wallet disconnection or address/chain change.
  • Flexible Configuration: Allows custom configuration of Iron Session settings (password, cookie name) and support for Async Hooks (e.g., afterVerify, afterLogout).

💾 Installation

Requirements

  • Node.js 20+
  • TypeScript 5.9+
  • Wagmi v2+
  • Viem v2+
  • Iron Session v8+
# Using pnpm (recommended)
pnpm add @tuwaio/satellite-siwe-next-auth siwe iron-session wagmi @wagmi/core viem

# Using npm
npm install @tuwaio/satellite-siwe-next-auth siwe iron-session wagmi @wagmi/core viem

Environment Setup

This package requires two private server environment variables for security:

| Variable | Description | | :--- | :--- | | SIWE_SESSION_SECRET | Required. A cryptographically secure secret (minimum 32 characters) used by Iron Session to encrypt the session cookie. | | SIWE_SESSION_URL | Required. The full base URL of your application (e.g., http://localhost:3000 or https://myapp.com). Used for SIWE domain verification. |

Example .env.local:

SIWE_SESSION_SECRET="oowX51fBPYHSVQxPbktPrfM8Lb3Kbeg3oQ6aCKdeLLo="
SIWE_SESSION_URL="http://localhost:3000"

🚀 Quick Start

1. Server Setup (API Route)

Create the dynamic API route file at src/api/siwe/[...siwe]/route.ts and export the handler from the package. This handles /login, /logout, and /session requests.

// src/api/siwe/[...siwe]/route.ts

import { createSiweApiHandler } from '@tuwaio/satellite-siwe-next-auth/server';

// Initialize the handler. Configuration is read from the .env file by default.
const siweApiHandler = createSiweApiHandler();

// Export the methods expected by Next.js App Router
export const { GET, POST, DELETE } = siweApiHandler;

2. Client Setup (Provider)

Wrap your application in the SiweNextAuthProvider. This provider manages the authentication state, session fetching, and handles auto-sign-out/re-authentication on wallet changes.

// src/providers/Providers.tsx

import { SiweNextAuthProvider } from '@tuwaio/satellite-siwe-next-auth';
// ... other imports (WagmiProvider, QueryClientProvider)

export function Providers({ children }: { children: React.ReactNode }) {
  return (
    <WagmiProvider config={wagmiConfig}>
      <QueryClientProvider client={queryClient}>
        {/* WAGMI AND REACT-QUERY MUST WRAP THE SIWE PROVIDER */}
        <SiweNextAuthProvider
          enabled={true}
          onSignOut={() => console.log('User signed out')}
          onSignIn={(session) => console.log('User signed in:', session)}
        >
          {children}
        </SiweNextAuthProvider>
      </QueryClientProvider>
    </WagmiProvider>
  );
}

3. Usage (Login Component)

Use the useSiweAuth hook to access the sign-in function and state.

// src/components/WalletConnect.tsx

import { useSiweAuth } from '@tuwaio/satellite-siwe-next-auth';
// ... other imports (Wagmi hooks, etc.)

export function SatelliteConnectProviders({ children }: { children: React.ReactNode }) {
  const { signInWithSiwe, isSignedIn, isRejected, enabled } = useSiweAuth();
  
  // Example usage: Pass signInWithSiwe as the connection handler to a wallet adapter
  // The adapter will call signInWithSiwe() after a wallet connection is established.
  return (
    <SatelliteConnectProvider
      adapter={[
        // Pass signInWithSiwe to your EVM adapter
        satelliteEVMAdapter(wagmiConfig, enabled ? signInWithSiwe : undefined), 
        // ...
      ]}
      autoConnect={true}
    >
      {/* ... your components */}
    </SatelliteConnectProvider>
  );
}

⚙️ Custom Configuration

The createSiweApiHandler accepts an optional configuration object to override session settings and define asynchronous hooks.

Configuration Parameters (SiweApiConfig Type)

| Parameter | Type | Default | Description | | :--- | :--- | :--- | :--- | | session.password | string | SIWE_SESSION_SECRET | Overrides the secret key for encryption. | | session.cookieName | string | 'satellite_siwe' | Overrides the name of the session cookie. | | session.cookieOptions | SiweCookieOptions | { maxAge: 30 days, secure: false (dev) } | Allows overriding standard cookie settings (e.g., maxAge). | | options.afterVerify | () => Promise<void> | undefined | Hook executed after the SIWE signature is cryptographically verified. Ideal for fetching user data. | | options.afterLogout | () => Promise<void> | undefined | Hook executed after the session cookie is destroyed. |

Example Custom Initialization

// src/api/siwe/[...siwe]/route.ts

import { createSiweApiHandler } from '@tuwaio/satellite-siwe-next-auth/server';

const siweApiHandler = createSiweApiHandler({
    // Custom Session Settings
    session: {
        cookieName: "my_app_session",
        cookieOptions: {
            maxAge: 60 * 60 * 24 * 7, // 7 days
        }
    },
    // Custom Hooks
    options: {
        afterVerify: async () => {
            // This logic runs on the server side after a valid signature is confirmed.
            console.log("User verified, ready to create DB record.");
        },
        afterLogout: () => {
            console.log("User session destroyed.");
        }
    }
});

export const { GET, POST, DELETE } = siweApiHandler;

🤝 Contributing & Support

Contributions are welcome! Please read our main Contribution Guidelines.

If you find this library useful, please consider supporting its development. Every contribution helps!

➡️ View Support Options

📄 License

This project is licensed under the Apache-2.0 License - see the LICENSE file for details.