@neondatabase/auth 0.1.0-beta.2 → 0.1.0-beta.20
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 +112 -18
- package/dist/{adapter-core-C12KoaiU.d.mts → adapter-core-23fYTUxT.d.mts} +175 -627
- package/dist/{adapter-core-BDOw-gBC.mjs → adapter-core-8s6XdCco.mjs} +392 -69
- package/dist/{better-auth-react-adapter-FnBHa2nr.mjs → better-auth-react-adapter-D9tIaEyQ.mjs} +10 -8
- package/dist/better-auth-react-adapter-QFe5RtaM.d.mts +2170 -0
- package/dist/better-auth-types-BUiggBfa.d.mts +9 -0
- package/dist/chunk-VCZJYX65-CLnrj1o7-D6ZQkcc_.mjs +543 -0
- package/dist/constants-2bpp2_-f.mjs +30 -0
- package/dist/index-Bga0CzOO.d.mts +49 -0
- package/dist/index.d.mts +5 -98
- package/dist/index.mjs +2 -1
- package/dist/middleware-C7jHeulu.mjs +303 -0
- package/dist/{neon-auth-C9XTFffv.mjs → neon-auth-2f58U8_-.mjs} +7 -4
- package/dist/neon-auth-CDYpC_O1.d.mts +107 -0
- package/dist/next/index.d.mts +139 -303
- package/dist/next/index.mjs +37 -174
- package/dist/next/server/index.d.mts +389 -0
- package/dist/next/server/index.mjs +432 -0
- package/dist/react/adapters/index.d.mts +5 -4
- package/dist/react/adapters/index.mjs +2 -1
- package/dist/react/index.d.mts +6 -5
- package/dist/react/index.mjs +5 -92
- package/dist/react/ui/index.d.mts +1 -1
- package/dist/react/ui/index.mjs +3 -91
- package/dist/react/ui/server.mjs +1 -1
- package/dist/{supabase-adapter-ggmqWgPe.mjs → supabase-adapter-BYMJSxOT.mjs} +72 -167
- package/dist/supabase-adapter-Dr-pKvPt.d.mts +2258 -0
- package/dist/types/index.d.mts +4 -0
- package/dist/types/index.mjs +3 -0
- package/dist/ui/.safelist.html +3 -0
- package/dist/ui/css.css +2 -2
- package/dist/ui/tailwind.css +3 -2
- package/dist/ui/theme-inline.css +39 -0
- package/dist/ui/theme.css +125 -49
- package/dist/ui-Cg1EZzGG.mjs +12104 -0
- package/dist/vanilla/adapters/index.d.mts +4 -3
- package/dist/vanilla/adapters/index.mjs +2 -1
- package/dist/vanilla/index.d.mts +4 -3
- package/dist/vanilla/index.mjs +2 -1
- package/llms.txt +172 -0
- package/package.json +21 -10
- package/dist/better-auth-react-adapter-BXL48HIU.d.mts +0 -722
- package/dist/supabase-adapter-crabDnl2.d.mts +0 -128
- package/dist/ui-CNFBSekF.mjs +0 -401
- /package/dist/{adapters-Dkx0zoMR.mjs → adapters-B7YKkjaL.mjs} +0 -0
- /package/dist/{index-C-svZlpj.d.mts → index-BHI9uOzY.d.mts} +0 -0
- /package/dist/{index-DuDD6cIY.d.mts → index-CSe4aQIZ.d.mts} +0 -0
- /package/dist/{index-UW23fDSn.d.mts → index-LhFpnU-f.d.mts} +0 -0
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@neondatabase/auth)
|
|
4
4
|
[](https://www.npmjs.com/package/@neondatabase/auth)
|
|
5
5
|
[](https://www.typescriptlang.org/)
|
|
6
|
-
[](https://github.com/neondatabase
|
|
6
|
+
[](https://github.com/neondatabase/neon-js/blob/main/LICENSE)
|
|
7
7
|
|
|
8
8
|
Authentication adapters for Neon Auth, supporting multiple auth providers.
|
|
9
9
|
|
|
@@ -19,9 +19,35 @@ This package is designed to work seamlessly with Neon's authentication infrastru
|
|
|
19
19
|
|
|
20
20
|
- **Simple default API** - Works out of the box with Better Auth patterns
|
|
21
21
|
- **Optional adapters** - Switch API styles for migrations or preferences
|
|
22
|
+
- **Anonymous access** - Optional RLS-based data access for unauthenticated users
|
|
22
23
|
- **Performance optimizations** - Session caching and request deduplication
|
|
23
24
|
- **TypeScript support** - Fully typed with strict type checking
|
|
24
25
|
|
|
26
|
+
## Why @neondatabase/auth?
|
|
27
|
+
|
|
28
|
+
### vs. better-auth/client
|
|
29
|
+
|
|
30
|
+
`@neondatabase/auth` is a wrapper around Better Auth that provides:
|
|
31
|
+
|
|
32
|
+
**API Flexibility:**
|
|
33
|
+
- Multiple adapters (Supabase-compatible, React hooks, vanilla)
|
|
34
|
+
- Restricted options to match Neon Auth capabilities
|
|
35
|
+
|
|
36
|
+
**Neon Auth Integration:**
|
|
37
|
+
- Automatic `token_verifier` on OAuth callback
|
|
38
|
+
- Pre-configured plugins for Neon Auth
|
|
39
|
+
- Automatic JWT extraction from sessions
|
|
40
|
+
- Popup-based OAuth flow for iframes
|
|
41
|
+
|
|
42
|
+
**Built-in Enhancements:**
|
|
43
|
+
- Session caching (60s TTL)
|
|
44
|
+
- Request deduplication
|
|
45
|
+
- Event system
|
|
46
|
+
- Cross-tab sync
|
|
47
|
+
- Token refresh detection
|
|
48
|
+
|
|
49
|
+
If you're not using Neon Auth, you should probably use `better-auth/client` directly for more flexibility.
|
|
50
|
+
|
|
25
51
|
## Installation
|
|
26
52
|
|
|
27
53
|
```bash
|
|
@@ -144,6 +170,23 @@ function MyComponent() {
|
|
|
144
170
|
}
|
|
145
171
|
```
|
|
146
172
|
|
|
173
|
+
## Anonymous Access
|
|
174
|
+
|
|
175
|
+
Enable `allowAnonymous` to let unauthenticated users access data via RLS policies:
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
import { createAuthClient } from '@neondatabase/auth';
|
|
179
|
+
|
|
180
|
+
const auth = createAuthClient('https://your-auth-server.com', {
|
|
181
|
+
allowAnonymous: true, // Enable anonymous data access
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// Get token - returns anonymous token if no user session exists
|
|
185
|
+
const token = await auth.getJWTToken?.();
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
This is useful when you want to allow read-only public access to certain data while still enforcing RLS policies.
|
|
189
|
+
|
|
147
190
|
## API Reference
|
|
148
191
|
|
|
149
192
|
### createAuthClient(url, config?)
|
|
@@ -153,6 +196,7 @@ Factory function to create an auth client.
|
|
|
153
196
|
**Parameters:**
|
|
154
197
|
- `url` - The auth service URL (required)
|
|
155
198
|
- `config.adapter` - Optional adapter factory function (e.g., `SupabaseAuthAdapter()`)
|
|
199
|
+
- `config.allowAnonymous` - When `true`, returns an anonymous token if no user session exists (default: `false`)
|
|
156
200
|
|
|
157
201
|
**Returns:** The adapter's public API (varies by adapter type)
|
|
158
202
|
|
|
@@ -215,40 +259,90 @@ Multiple concurrent `getSession()` calls are automatically deduplicated:
|
|
|
215
259
|
|
|
216
260
|
For Next.js projects, this package provides built-in integration via `@neondatabase/auth/next`. See the [Next.js Setup Guide](./NEXT-JS.md) for:
|
|
217
261
|
|
|
218
|
-
-
|
|
219
|
-
-
|
|
220
|
-
-
|
|
262
|
+
- Setting up the auth handler with `authApiHandler()`
|
|
263
|
+
- Protecting routes with `neonAuthMiddleware()`
|
|
264
|
+
- Creating the auth client with `createAuthClient()` for client components
|
|
265
|
+
- Configuring the `NeonAuthUIProvider` with Email OTP, Social Login, and Organizations
|
|
266
|
+
- Creating auth pages (`AuthView`, `AccountView`, `OrganizationView`)
|
|
221
267
|
- Importing styles (with or without Tailwind CSS)
|
|
268
|
+
- Accessing session data with `neonAuth()` in server components
|
|
269
|
+
- Using `authClient.useSession()` hook in client components
|
|
270
|
+
- Server-side auth operations with `createAuthServer()` from `@neondatabase/auth/next/server`
|
|
222
271
|
|
|
223
|
-
##
|
|
272
|
+
## UI Components
|
|
224
273
|
|
|
225
|
-
|
|
274
|
+
Pre-built login forms and auth pages are included. No extra installation needed.
|
|
226
275
|
|
|
227
|
-
|
|
228
|
-
|--------|----------|
|
|
229
|
-
| `@neondatabase/auth/ui/css` | Pre-built styles (~47KB) |
|
|
230
|
-
| `@neondatabase/auth/ui/tailwind` | Tailwind-ready CSS |
|
|
276
|
+
### 1. Import CSS
|
|
231
277
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
278
|
+
**Without Tailwind CSS:**
|
|
279
|
+
```typescript
|
|
280
|
+
import '@neondatabase/auth/ui/css';
|
|
281
|
+
```
|
|
235
282
|
|
|
236
|
-
|
|
283
|
+
**With Tailwind CSS v4:**
|
|
284
|
+
```css
|
|
237
285
|
@import 'tailwindcss';
|
|
238
286
|
@import '@neondatabase/auth/ui/tailwind';
|
|
239
287
|
```
|
|
240
288
|
|
|
289
|
+
### 2. Setup Provider
|
|
290
|
+
|
|
291
|
+
```typescript
|
|
292
|
+
"use client"
|
|
293
|
+
|
|
294
|
+
import { NeonAuthUIProvider } from "@neondatabase/auth/react/ui"
|
|
295
|
+
import { createAuthClient } from "@neondatabase/auth"
|
|
296
|
+
import "@neondatabase/auth/ui/css"
|
|
297
|
+
|
|
298
|
+
const authClient = createAuthClient('https://your-auth-url.com')
|
|
299
|
+
|
|
300
|
+
export function AuthProvider({ children }) {
|
|
301
|
+
return (
|
|
302
|
+
<NeonAuthUIProvider authClient={authClient} redirectTo="/dashboard">
|
|
303
|
+
{children}
|
|
304
|
+
</NeonAuthUIProvider>
|
|
305
|
+
)
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### 3. Use Components
|
|
310
|
+
|
|
311
|
+
**Option A: Full Auth Pages (Recommended)**
|
|
312
|
+
|
|
313
|
+
Use `AuthView` to render complete auth flows based on the URL path:
|
|
314
|
+
|
|
315
|
+
```typescript
|
|
316
|
+
import { AuthView } from "@neondatabase/auth/react/ui"
|
|
317
|
+
|
|
318
|
+
// Renders sign-in, sign-up, forgot-password, etc. based on path
|
|
319
|
+
<AuthView path="sign-in" />
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
**Option B: Individual Components**
|
|
323
|
+
|
|
324
|
+
```typescript
|
|
325
|
+
import { SignInForm, UserButton } from "@neondatabase/auth/react/ui"
|
|
326
|
+
|
|
327
|
+
<SignInForm />
|
|
328
|
+
<UserButton />
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
Available components: `SignInForm`, `SignUpForm`, `UserButton`, `AuthView`, `AccountView`, `OrganizationView`
|
|
332
|
+
|
|
333
|
+
For Next.js with dynamic routes, see the [Next.js Setup Guide](./NEXT-JS.md).
|
|
334
|
+
|
|
335
|
+
For full documentation and theming, see [`@neondatabase/auth-ui`](../auth-ui).
|
|
336
|
+
|
|
241
337
|
## Related Packages
|
|
242
338
|
|
|
243
339
|
- [`@neondatabase/neon-js`](../neon-js) - Full SDK with database and auth integration
|
|
244
|
-
- [`@neondatabase/postgrest-js`](../postgrest-js) -
|
|
245
|
-
- [`@neondatabase/auth-ui`](../auth-ui) - UI components for Neon Auth
|
|
340
|
+
- [`@neondatabase/postgrest-js`](../postgrest-js) - PostgREST client without auth
|
|
246
341
|
|
|
247
342
|
## Resources
|
|
248
343
|
|
|
249
|
-
- [Neon Auth Documentation](https://neon.
|
|
344
|
+
- [Neon Auth Documentation](https://neon.com/docs/neon-auth)
|
|
250
345
|
- [Better Auth Documentation](https://www.better-auth.com/docs)
|
|
251
|
-
- [Supabase Auth Reference](https://supabase.com/docs/reference/javascript/auth-signup)
|
|
252
346
|
|
|
253
347
|
## Support
|
|
254
348
|
|