@neondatabase/auth 0.1.0-beta.2 → 0.1.0-beta.21

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.
Files changed (45) hide show
  1. package/README.md +112 -18
  2. package/dist/{adapter-core-BDOw-gBC.mjs → adapter-core-PD5NQpLE.mjs} +392 -69
  3. package/dist/{adapter-core-C12KoaiU.d.mts → adapter-core-y53SWo8w.d.mts} +181 -627
  4. package/dist/{better-auth-react-adapter-FnBHa2nr.mjs → better-auth-react-adapter-B0XIXPUH.mjs} +10 -8
  5. package/dist/better-auth-react-adapter-B7zoQmoL.d.mts +2170 -0
  6. package/dist/chunk-VCZJYX65-CLnrj1o7-D6ZQkcc_.mjs +543 -0
  7. package/dist/constants-2bpp2_-f.mjs +30 -0
  8. package/dist/index.d.mts +4 -98
  9. package/dist/index.mjs +2 -1
  10. package/dist/{neon-auth-C9XTFffv.mjs → neon-auth-DUbqaO2v.mjs} +7 -4
  11. package/dist/neon-auth-oDgy6lQm.d.mts +107 -0
  12. package/dist/next/index.d.mts +76 -303
  13. package/dist/next/index.mjs +6 -174
  14. package/dist/next/server/index.d.mts +433 -0
  15. package/dist/next/server/index.mjs +731 -0
  16. package/dist/react/adapters/index.d.mts +4 -4
  17. package/dist/react/adapters/index.mjs +2 -1
  18. package/dist/react/index.d.mts +5 -5
  19. package/dist/react/index.mjs +5 -92
  20. package/dist/react/ui/index.d.mts +1 -1
  21. package/dist/react/ui/index.mjs +3 -91
  22. package/dist/react/ui/server.mjs +1 -1
  23. package/dist/{supabase-adapter-ggmqWgPe.mjs → supabase-adapter-Bdw6aPGx.mjs} +72 -167
  24. package/dist/supabase-adapter-Dm56RKRF.d.mts +2258 -0
  25. package/dist/types/index.d.mts +3 -0
  26. package/dist/types/index.mjs +3 -0
  27. package/dist/ui/.safelist.html +3 -0
  28. package/dist/ui/css.css +2 -2
  29. package/dist/ui/tailwind.css +4 -3
  30. package/dist/ui/theme-inline.css +44 -0
  31. package/dist/ui/theme.css +221 -118
  32. package/dist/ui-CrxGg6vQ.mjs +12113 -0
  33. package/dist/vanilla/adapters/index.d.mts +3 -3
  34. package/dist/vanilla/adapters/index.mjs +2 -1
  35. package/dist/vanilla/index.d.mts +3 -3
  36. package/dist/vanilla/index.mjs +2 -1
  37. package/llms.txt +172 -0
  38. package/package.json +22 -11
  39. package/dist/better-auth-react-adapter-BXL48HIU.d.mts +0 -722
  40. package/dist/supabase-adapter-crabDnl2.d.mts +0 -128
  41. package/dist/ui-CNFBSekF.mjs +0 -401
  42. /package/dist/{adapters-Dkx0zoMR.mjs → adapters-B7YKkjaL.mjs} +0 -0
  43. /package/dist/{index-C-svZlpj.d.mts → index-CPnFzULh.d.mts} +0 -0
  44. /package/dist/{index-DuDD6cIY.d.mts → index-CzsGMS7C.d.mts} +0 -0
  45. /package/dist/{index-UW23fDSn.d.mts → index-OEBbnNdr.d.mts} +0 -0
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![npm version](https://img.shields.io/npm/v/@neondatabase/auth.svg)](https://www.npmjs.com/package/@neondatabase/auth)
4
4
  [![npm downloads](https://img.shields.io/npm/dm/@neondatabase/auth.svg)](https://www.npmjs.com/package/@neondatabase/auth)
5
5
  [![TypeScript](https://img.shields.io/badge/TypeScript-5.0%2B-blue.svg)](https://www.typescriptlang.org/)
6
- [![License](https://img.shields.io/npm/l/@neondatabase/auth.svg)](https://github.com/neondatabase-labs/neon-js/blob/main/LICENSE)
6
+ [![License](https://img.shields.io/npm/l/@neondatabase/auth.svg)](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
- - Creating API route handlers with `toNextJsHandler()`
219
- - Setting up the auth client for client components
220
- - Configuring the `NeonAuthUIProvider`
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
- ## CSS for UI Components
272
+ ## UI Components
224
273
 
225
- If you're using `@neondatabase/auth-ui` components, CSS is conveniently re-exported from this package:
274
+ Pre-built login forms and auth pages are included. No extra installation needed.
226
275
 
227
- | Export | Use Case |
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
- ```css
233
- /* Without Tailwind */
234
- @import '@neondatabase/auth/ui/css';
278
+ **Without Tailwind CSS:**
279
+ ```typescript
280
+ import '@neondatabase/auth/ui/css';
281
+ ```
235
282
 
236
- /* With Tailwind CSS v4 */
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) - PostgreSQL client without auth
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.tech/docs/neon-auth)
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