@neondatabase/auth 0.1.0-beta.8 → 0.2.0-beta.1

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 +108 -18
  2. package/dist/{adapter-core-Bw9mn_AS.d.mts → adapter-core-CnrOXh1T.d.mts} +246 -280
  3. package/dist/{adapter-core-C_NEMs0b.mjs → adapter-core-CtmnMMJ7.mjs} +392 -67
  4. package/dist/better-auth-react-adapter-DNi5PC5D.d.mts +2170 -0
  5. package/dist/{better-auth-react-adapter-BbM3jLLv.mjs → better-auth-react-adapter-Dv-o6A6O.mjs} +10 -8
  6. package/dist/{chunk-5DLVHPZS-Bxj7snpZ-DoVNlsyk.mjs → chunk-VCZJYX65-CLnrj1o7-D6ZQkcc_.mjs} +13 -3
  7. package/dist/constants-Cupc_bln.mjs +28 -0
  8. package/dist/index.d.mts +4 -98
  9. package/dist/index.mjs +2 -1
  10. package/dist/neon-auth-BEGCfAe6.d.mts +107 -0
  11. package/dist/{neon-auth-DdlToh7_.mjs → neon-auth-Cs2cWh1B.mjs} +7 -4
  12. package/dist/next/index.d.mts +61 -170
  13. package/dist/next/index.mjs +4 -311
  14. package/dist/next/server/index.d.mts +538 -0
  15. package/dist/next/server/index.mjs +1373 -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 +4 -3
  20. package/dist/react/ui/index.d.mts +1 -1
  21. package/dist/react/ui/index.mjs +2 -2
  22. package/dist/react/ui/server.mjs +1 -1
  23. package/dist/{supabase-adapter-CAqbpOC7.mjs → supabase-adapter-BlcGPyOf.mjs} +28 -45
  24. package/dist/supabase-adapter-DUqw2fw8.d.mts +2258 -0
  25. package/dist/types/index.d.mts +2 -7
  26. package/dist/ui/.safelist.html +3 -0
  27. package/dist/ui/css.css +2 -2
  28. package/dist/ui/tailwind.css +4 -3
  29. package/dist/ui/theme-inline.css +44 -0
  30. package/dist/ui/theme.css +221 -118
  31. package/dist/{ui-aMoA-9nq.mjs → ui-COLWzDsu.mjs} +6024 -3004
  32. package/dist/vanilla/adapters/index.d.mts +3 -3
  33. package/dist/vanilla/adapters/index.mjs +2 -1
  34. package/dist/vanilla/index.d.mts +3 -3
  35. package/dist/vanilla/index.mjs +2 -1
  36. package/llms.txt +330 -0
  37. package/package.json +17 -10
  38. package/dist/better-auth-react-adapter-JoscqoDc.d.mts +0 -722
  39. package/dist/better-auth-types-CE4hLv9E.d.mts +0 -9
  40. package/dist/supabase-adapter-Clxlqg1x.d.mts +0 -127
  41. /package/dist/{adapters-D0mxG3F-.mjs → adapters-B7YKkjaL.mjs} +0 -0
  42. /package/dist/{adapters-Df6Dd3KK.mjs → adapters-CivF9wql.mjs} +0 -0
  43. /package/dist/{index-ClXLQ1fw.d.mts → index-CPnFzULh.d.mts} +0 -0
  44. /package/dist/{index-BXlAjlSt.d.mts → index-CzsGMS7C.d.mts} +0 -0
  45. /package/dist/{index-DCQ5Y2ED.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
 
@@ -213,43 +257,89 @@ Multiple concurrent `getSession()` calls are automatically deduplicated:
213
257
 
214
258
  ## Next.js Integration
215
259
 
216
- For Next.js projects, this package provides built-in integration via `@neondatabase/auth/next`. See the [Next.js Setup Guide](./NEXT-JS.md) for:
260
+ For Next.js projects, this package provides built-in integration via `@neondatabase/auth/next`.
261
+ See the [Next.js Setup Guide](./NEXT-JS.md) for comprehensive documentation including:
217
262
 
218
- - Setting up the auth handler with `authApiHandler()`
219
- - Protecting routes with `neonAuthMiddleware()`
220
- - Creating the auth client with `createAuthClient()` for client components
263
+ - Setting up auth server instance with `createNeonAuth()` for handler, middleware and api methods
264
+ - Client-side auth with `createAuthClient()` for client components
221
265
  - Configuring the `NeonAuthUIProvider` with Email OTP, Social Login, and Organizations
222
266
  - Creating auth pages (`AuthView`, `AccountView`, `OrganizationView`)
223
267
  - Importing styles (with or without Tailwind CSS)
224
- - Accessing session data with `neonAuth()` in server components
225
268
  - Using `authClient.useSession()` hook in client components
226
269
 
227
- ## CSS for UI Components
270
+ ## UI Components
228
271
 
229
- Styles for Neon Auth UI components are available from this package:
272
+ Pre-built login forms and auth pages are included. No extra installation needed.
230
273
 
231
- | Export | Use Case |
232
- |--------|----------|
233
- | `@neondatabase/auth/ui/css` | Pre-built styles (~47KB) |
234
- | `@neondatabase/auth/ui/tailwind` | Tailwind-ready CSS |
274
+ ### 1. Import CSS
235
275
 
236
- ```css
237
- /* Without Tailwind */
238
- @import '@neondatabase/auth/ui/css';
276
+ **Without Tailwind CSS:**
277
+ ```typescript
278
+ import '@neondatabase/auth/ui/css';
279
+ ```
239
280
 
240
- /* With Tailwind CSS v4 */
281
+ **With Tailwind CSS v4:**
282
+ ```css
241
283
  @import 'tailwindcss';
242
284
  @import '@neondatabase/auth/ui/tailwind';
243
285
  ```
244
286
 
287
+ ### 2. Setup Provider
288
+
289
+ ```typescript
290
+ "use client"
291
+
292
+ import { NeonAuthUIProvider } from "@neondatabase/auth/react/ui"
293
+ import { createAuthClient } from "@neondatabase/auth"
294
+ import "@neondatabase/auth/ui/css"
295
+
296
+ const authClient = createAuthClient('https://your-auth-url.com')
297
+
298
+ export function AuthProvider({ children }) {
299
+ return (
300
+ <NeonAuthUIProvider authClient={authClient} redirectTo="/dashboard">
301
+ {children}
302
+ </NeonAuthUIProvider>
303
+ )
304
+ }
305
+ ```
306
+
307
+ ### 3. Use Components
308
+
309
+ **Option A: Full Auth Pages (Recommended)**
310
+
311
+ Use `AuthView` to render complete auth flows based on the URL path:
312
+
313
+ ```typescript
314
+ import { AuthView } from "@neondatabase/auth/react/ui"
315
+
316
+ // Renders sign-in, sign-up, forgot-password, etc. based on path
317
+ <AuthView path="sign-in" />
318
+ ```
319
+
320
+ **Option B: Individual Components**
321
+
322
+ ```typescript
323
+ import { SignInForm, UserButton } from "@neondatabase/auth/react/ui"
324
+
325
+ <SignInForm />
326
+ <UserButton />
327
+ ```
328
+
329
+ Available components: `SignInForm`, `SignUpForm`, `UserButton`, `AuthView`, `AccountView`, `OrganizationView`
330
+
331
+ For Next.js with dynamic routes, see the [Next.js Setup Guide](./NEXT-JS.md).
332
+
333
+ For full documentation and theming, see [`@neondatabase/auth-ui`](../auth-ui).
334
+
245
335
  ## Related Packages
246
336
 
247
337
  - [`@neondatabase/neon-js`](../neon-js) - Full SDK with database and auth integration
248
- - [`@neondatabase/postgrest-js`](../postgrest-js) - PostgreSQL client without auth
338
+ - [`@neondatabase/postgrest-js`](../postgrest-js) - PostgREST client without auth
249
339
 
250
340
  ## Resources
251
341
 
252
- - [Neon Auth Documentation](https://neon.tech/docs/neon-auth)
342
+ - [Neon Auth Documentation](https://neon.com/docs/neon-auth)
253
343
  - [Better Auth Documentation](https://www.better-auth.com/docs)
254
344
 
255
345
  ## Support