@tuwaio/satellite-siwe-next-auth 1.0.0-fix-watcher-alpha.3.b979b45 → 1.0.0-fix-error-handling-alpha.2.5165cfe

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  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.
8
8
 
9
- -----
9
+ ---
10
10
 
11
11
  ## 🏛️ What is `@tuwaio/satellite-siwe-next-auth`?
12
12
 
@@ -14,9 +14,9 @@ A robust connector module for enabling secure Web3 authentication (Sign-In with
14
14
 
15
15
  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.
16
16
 
17
- Built on top of **Wagmi/Viem** for signature generation.
17
+ Built on top of **Wagmi/Viem** for signature generation and verification.
18
18
 
19
- -----
19
+ ---
20
20
 
21
21
  ## ✨ Key Features
22
22
 
@@ -25,24 +25,21 @@ Built on top of **Wagmi/Viem** for signature generation.
25
25
  - **Auto-Session Management:** Handles automatic re-authentication and session cleanup upon wallet disconnection or address/chain change.
26
26
  - **Flexible Configuration:** Allows custom configuration of Iron Session settings (password, cookie name) and support for **Async Hooks** (e.g., `afterVerify`, `afterLogout`).
27
27
 
28
- -----
28
+ ---
29
29
 
30
30
  ## 💾 Installation
31
31
 
32
32
  ### Requirements
33
33
 
34
- - Node.js 20+
34
+ - Node.js 20-24
35
35
  - TypeScript 5.9+
36
36
  - Wagmi v2+
37
37
  - Viem v2+
38
38
  - Iron Session v8+
39
39
 
40
40
  ```bash
41
- # Using pnpm (recommended)
41
+ # Using pnpm (recommended), but you can use npm, yarn or bun as well
42
42
  pnpm add @tuwaio/satellite-siwe-next-auth siwe iron-session wagmi @wagmi/core viem
43
-
44
- # Using npm
45
- npm install @tuwaio/satellite-siwe-next-auth siwe iron-session wagmi @wagmi/core viem
46
43
  ```
47
44
 
48
45
  ### Environment Setup
@@ -54,23 +51,23 @@ This package requires two **private** server environment variables for security:
54
51
  | `SIWE_SESSION_SECRET` | **Required.** A cryptographically secure secret (minimum 32 characters) used by Iron Session to encrypt the session cookie. |
55
52
  | `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. |
56
53
 
57
- **Example `.env.local`:**
54
+ **Example `.env`:**
58
55
 
59
56
  ```env
60
57
  SIWE_SESSION_SECRET="oowX51fBPYHSVQxPbktPrfM8Lb3Kbeg3oQ6aCKdeLLo="
61
58
  SIWE_SESSION_URL="http://localhost:3000"
62
59
  ```
63
60
 
64
- -----
61
+ ---
65
62
 
66
63
  ## 🚀 Quick Start
67
64
 
68
65
  ### 1. Server Setup (API Route)
69
66
 
70
- 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.
67
+ Create the dynamic API route file at **`app/api/siwe/[...siwe]/route.ts`** and export the handler from the package. This handles `/login`, `/logout`, and `/session` requests.
71
68
 
72
69
  ```typescript
73
- // src/api/siwe/[...siwe]/route.ts
70
+ // app/api/siwe/[...siwe]/route.ts
74
71
 
75
72
  import { createSiweApiHandler } from '@tuwaio/satellite-siwe-next-auth/server';
76
73
 
@@ -81,22 +78,40 @@ const siweApiHandler = createSiweApiHandler();
81
78
  export const { GET, POST, DELETE } = siweApiHandler;
82
79
  ```
83
80
 
84
- ### 2. Client Setup (Provider)
81
+ ### 2. Client Setup (Providers)
85
82
 
86
83
  Wrap your application in the `SiweNextAuthProvider`. This provider manages the authentication state, session fetching, and handles auto-sign-out/re-authentication on wallet changes.
87
84
 
88
85
  ```tsx
89
86
  // src/providers/Providers.tsx
90
87
 
88
+ 'use client';
89
+
90
+ import { ReactNode, useState } from 'react';
91
+ import { WagmiProvider, createConfig, http } from 'wagmi';
92
+ import { mainnet, sepolia } from 'viem/chains';
93
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
91
94
  import { SiweNextAuthProvider } from '@tuwaio/satellite-siwe-next-auth';
92
- // ... other imports (WagmiProvider, QueryClientProvider)
93
95
 
94
- export function Providers({ children }: { children: React.ReactNode }) {
96
+ // 1. Configure Wagmi
97
+ export const wagmiConfig = createConfig({
98
+ chains: [mainnet, sepolia],
99
+ transports: {
100
+ [mainnet.id]: http(),
101
+ [sepolia.id]: http(),
102
+ },
103
+ });
104
+
105
+ // 2. Create Query Client
106
+ const queryClient = new QueryClient();
107
+
108
+ export function Providers({ children }: { children: ReactNode }) {
95
109
  return (
96
110
  <WagmiProvider config={wagmiConfig}>
97
111
  <QueryClientProvider client={queryClient}>
98
- {/* WAGMI AND REACT-QUERY MUST WRAP THE SIWE PROVIDER */}
112
+ {/* SiweNextAuthProvider must be inside Wagmi and QueryClient providers */}
99
113
  <SiweNextAuthProvider
114
+ wagmiConfig={wagmiConfig}
100
115
  enabled={true}
101
116
  onSignOut={() => console.log('User signed out')}
102
117
  onSignIn={(session) => console.log('User signed in:', session)}
@@ -109,37 +124,43 @@ export function Providers({ children }: { children: React.ReactNode }) {
109
124
  }
110
125
  ```
111
126
 
112
- ### 3. Usage (Login Component)
127
+ ### 3. Integrating with Satellite Connect
113
128
 
114
- Use the `useSiweAuth` hook to access the sign-in function and state.
129
+ Use the `useSiweAuth` hook to integrate SIWE authentication into the `SatelliteConnectProvider`.
115
130
 
116
131
  ```tsx
117
- // src/components/WalletConnect.tsx
132
+ // src/providers/SatelliteSiweProvider.tsx
133
+
134
+ 'use client';
118
135
 
136
+ import { ReactNode } from 'react';
137
+ import { SatelliteConnectProvider, EVMConnectorsWatcher } from '@tuwaio/satellite-react';
138
+ import { satelliteEVMAdapter } from '@tuwaio/satellite-evm';
119
139
  import { useSiweAuth } from '@tuwaio/satellite-siwe-next-auth';
120
- // ... other imports (Wagmi hooks, etc.)
140
+ import { wagmiConfig } from './Providers'; // Your Wagmi config
141
+
142
+ export function SatelliteSiweProvider({ children }: { children: ReactNode }) {
143
+ // Get SIWE auth state and methods
144
+ const { signInWithSiwe, enabled: siweEnabled, isSignedIn, isRejected } = useSiweAuth();
121
145
 
122
- export function SatelliteConnectProviders({ children }: { children: React.ReactNode }) {
123
- const { signInWithSiwe, isSignedIn, isRejected, enabled } = useSiweAuth();
124
-
125
- // Example usage: Pass signInWithSiwe as the connection handler to a wallet adapter
126
- // The adapter will call signInWithSiwe() after a wallet connection is established.
127
146
  return (
128
147
  <SatelliteConnectProvider
129
- adapter={[
130
- // Pass signInWithSiwe to your EVM adapter
131
- satelliteEVMAdapter(wagmiConfig, enabled ? signInWithSiwe : undefined),
132
- // ...
133
- ]}
148
+ // Pass the EVM adapter with SIWE integration
149
+ adapter={satelliteEVMAdapter(wagmiConfig, siweEnabled ? signInWithSiwe : undefined)}
134
150
  autoConnect={true}
135
151
  >
136
- {/* ... your components */}
152
+ {/* EVMConnectorsWatcher handles disconnections and account changes */}
153
+ <EVMConnectorsWatcher
154
+ wagmiConfig={wagmiConfig}
155
+ siwe={{ isSignedIn, isRejected, enabled: siweEnabled }}
156
+ />
157
+ {children}
137
158
  </SatelliteConnectProvider>
138
159
  );
139
160
  }
140
161
  ```
141
162
 
142
- -----
163
+ ---
143
164
 
144
165
  ## ⚙️ Custom Configuration
145
166
 
@@ -158,34 +179,34 @@ The `createSiweApiHandler` accepts an optional configuration object to override
158
179
  ### Example Custom Initialization
159
180
 
160
181
  ```typescript
161
- // src/api/siwe/[...siwe]/route.ts
182
+ // app/api/siwe/[...siwe]/route.ts
162
183
 
163
184
  import { createSiweApiHandler } from '@tuwaio/satellite-siwe-next-auth/server';
164
185
 
165
186
  const siweApiHandler = createSiweApiHandler({
166
- // Custom Session Settings
167
- session: {
168
- cookieName: "my_app_session",
169
- cookieOptions: {
170
- maxAge: 60 * 60 * 24 * 7, // 7 days
171
- }
187
+ // Custom Session Settings
188
+ session: {
189
+ cookieName: "my_app_session",
190
+ cookieOptions: {
191
+ maxAge: 60 * 60 * 24 * 7, // 7 days
192
+ }
193
+ },
194
+ // Custom Hooks
195
+ options: {
196
+ afterVerify: async () => {
197
+ // This logic runs on the server side after a valid signature is confirmed.
198
+ console.log("User verified, ready to create DB record.");
172
199
  },
173
- // Custom Hooks
174
- options: {
175
- afterVerify: async () => {
176
- // This logic runs on the server side after a valid signature is confirmed.
177
- console.log("User verified, ready to create DB record.");
178
- },
179
- afterLogout: () => {
180
- console.log("User session destroyed.");
181
- }
200
+ afterLogout: () => {
201
+ console.log("User session destroyed.");
182
202
  }
203
+ }
183
204
  });
184
205
 
185
206
  export const { GET, POST, DELETE } = siweApiHandler;
186
207
  ```
187
208
 
188
- -----
209
+ ---
189
210
 
190
211
  ## 🤝 Contributing & Support
191
212
 
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as SIWESession, a as SiweAuthContextType, b as SiweNextAuthProviderProps, U as UseSiweSignatureResult } from './types-D5pX4B-f.mjs';
2
- export { C as ConfigurableMessageOptions, G as GetSiweMessageOptions, h as Session, f as SiweApiConfig, e as SiweApiHooks, c as SiweCookieOptions, g as SiweSessionData, d as SiweSessionSettings, i as UnconfigurableMessageOptions } from './types-D5pX4B-f.mjs';
1
+ import { S as SIWESession, a as SiweAuthContextType, b as SiweNextAuthProviderProps, U as UseSiweSignatureResult } from './types-DYvmUmv4.mjs';
2
+ export { C as ConfigurableMessageOptions, G as GetSiweMessageOptions, c as Session, d as SiweApiConfig, e as SiweApiHooks, f as SiweCookieOptions, g as SiweSessionData, h as SiweSessionSettings, i as UnconfigurableMessageOptions } from './types-DYvmUmv4.mjs';
3
3
  import { Config } from '@wagmi/core';
4
4
  import * as react from 'react';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as SIWESession, a as SiweAuthContextType, b as SiweNextAuthProviderProps, U as UseSiweSignatureResult } from './types-D5pX4B-f.js';
2
- export { C as ConfigurableMessageOptions, G as GetSiweMessageOptions, h as Session, f as SiweApiConfig, e as SiweApiHooks, c as SiweCookieOptions, g as SiweSessionData, d as SiweSessionSettings, i as UnconfigurableMessageOptions } from './types-D5pX4B-f.js';
1
+ import { S as SIWESession, a as SiweAuthContextType, b as SiweNextAuthProviderProps, U as UseSiweSignatureResult } from './types-DYvmUmv4.js';
2
+ export { C as ConfigurableMessageOptions, G as GetSiweMessageOptions, c as Session, d as SiweApiConfig, e as SiweApiHooks, f as SiweCookieOptions, g as SiweSessionData, h as SiweSessionSettings, i as UnconfigurableMessageOptions } from './types-DYvmUmv4.js';
3
3
  import { Config } from '@wagmi/core';
4
4
  import * as react from 'react';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
@@ -1,5 +1,5 @@
1
1
  import { SessionOptions } from 'iron-session';
2
- import { f as SiweApiConfig } from '../types-D5pX4B-f.mjs';
2
+ import { d as SiweApiConfig } from '../types-DYvmUmv4.mjs';
3
3
  import { NextRequest } from 'next/server';
4
4
  import '@wagmi/core';
5
5
  import 'react';
@@ -1,5 +1,5 @@
1
1
  import { SessionOptions } from 'iron-session';
2
- import { f as SiweApiConfig } from '../types-D5pX4B-f.js';
2
+ import { d as SiweApiConfig } from '../types-DYvmUmv4.js';
3
3
  import { NextRequest } from 'next/server';
4
4
  import '@wagmi/core';
5
5
  import 'react';
@@ -155,4 +155,4 @@ interface SiweNextAuthProviderProps {
155
155
  children: ReactNode;
156
156
  }
157
157
 
158
- export type { ConfigurableMessageOptions as C, GetSiweMessageOptions as G, SIWESession as S, UseSiweSignatureResult as U, SiweAuthContextType as a, SiweNextAuthProviderProps as b, SiweCookieOptions as c, SiweSessionSettings as d, SiweApiHooks as e, SiweApiConfig as f, SiweSessionData as g, Session as h, UnconfigurableMessageOptions as i };
158
+ export type { ConfigurableMessageOptions as C, GetSiweMessageOptions as G, SIWESession as S, UseSiweSignatureResult as U, SiweAuthContextType as a, SiweNextAuthProviderProps as b, Session as c, SiweApiConfig as d, SiweApiHooks as e, SiweCookieOptions as f, SiweSessionData as g, SiweSessionSettings as h, UnconfigurableMessageOptions as i };
@@ -155,4 +155,4 @@ interface SiweNextAuthProviderProps {
155
155
  children: ReactNode;
156
156
  }
157
157
 
158
- export type { ConfigurableMessageOptions as C, GetSiweMessageOptions as G, SIWESession as S, UseSiweSignatureResult as U, SiweAuthContextType as a, SiweNextAuthProviderProps as b, SiweCookieOptions as c, SiweSessionSettings as d, SiweApiHooks as e, SiweApiConfig as f, SiweSessionData as g, Session as h, UnconfigurableMessageOptions as i };
158
+ export type { ConfigurableMessageOptions as C, GetSiweMessageOptions as G, SIWESession as S, UseSiweSignatureResult as U, SiweAuthContextType as a, SiweNextAuthProviderProps as b, Session as c, SiweApiConfig as d, SiweApiHooks as e, SiweCookieOptions as f, SiweSessionData as g, SiweSessionSettings as h, UnconfigurableMessageOptions as i };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuwaio/satellite-siwe-next-auth",
3
- "version": "1.0.0-fix-watcher-alpha.3.b979b45",
3
+ "version": "1.0.0-fix-error-handling-alpha.2.5165cfe",
4
4
  "private": false,
5
5
  "author": "Oleksandr Tkach",
6
6
  "license": "Apache-2.0",
@@ -60,16 +60,16 @@
60
60
  "wagmi": "3.x.x"
61
61
  },
62
62
  "devDependencies": {
63
- "@wagmi/core": "^3.1.0",
64
- "@types/react": "^19.2.7",
63
+ "@wagmi/core": "^3.3.1",
64
+ "@types/react": "^19.2.10",
65
65
  "siwe": "^3.0.0",
66
- "next": "16.1.1",
66
+ "next": "16.1.6",
67
67
  "iron-session": "^8.0.4",
68
- "react": "^19.2.3",
68
+ "react": "^19.2.4",
69
69
  "tsup": "^8.5.1",
70
70
  "typescript": "^5.9.3",
71
- "viem": "^2.43.5",
72
- "wagmi": "^3.2.0"
71
+ "viem": "^2.45.0",
72
+ "wagmi": "^3.4.1"
73
73
  },
74
74
  "scripts": {
75
75
  "start": "tsup src/index.ts --watch",