@neondatabase/auth 0.1.0-beta.9 → 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.
- package/README.md +108 -18
- package/dist/{adapter-core-Bw9mn_AS.d.mts → adapter-core-CnrOXh1T.d.mts} +246 -280
- package/dist/{adapter-core-C_NEMs0b.mjs → adapter-core-CtmnMMJ7.mjs} +392 -67
- package/dist/better-auth-react-adapter-DNi5PC5D.d.mts +2170 -0
- package/dist/{better-auth-react-adapter-BbM3jLLv.mjs → better-auth-react-adapter-Dv-o6A6O.mjs} +10 -8
- package/dist/{chunk-5DLVHPZS-Bxj7snpZ-DoVNlsyk.mjs → chunk-VCZJYX65-CLnrj1o7-D6ZQkcc_.mjs} +13 -3
- package/dist/constants-Cupc_bln.mjs +28 -0
- package/dist/index.d.mts +4 -98
- package/dist/index.mjs +2 -1
- package/dist/neon-auth-BEGCfAe6.d.mts +107 -0
- package/dist/{neon-auth-DdlToh7_.mjs → neon-auth-Cs2cWh1B.mjs} +7 -4
- package/dist/next/index.d.mts +61 -170
- package/dist/next/index.mjs +4 -311
- package/dist/next/server/index.d.mts +538 -0
- package/dist/next/server/index.mjs +1373 -0
- package/dist/react/adapters/index.d.mts +4 -4
- package/dist/react/adapters/index.mjs +2 -1
- package/dist/react/index.d.mts +5 -5
- package/dist/react/index.mjs +4 -3
- package/dist/react/ui/index.d.mts +1 -1
- package/dist/react/ui/index.mjs +2 -2
- package/dist/react/ui/server.mjs +1 -1
- package/dist/{supabase-adapter-CAqbpOC7.mjs → supabase-adapter-BlcGPyOf.mjs} +28 -45
- package/dist/supabase-adapter-DUqw2fw8.d.mts +2258 -0
- package/dist/types/index.d.mts +2 -7
- package/dist/ui/.safelist.html +3 -0
- package/dist/ui/css.css +2 -2
- package/dist/ui/tailwind.css +2 -1
- package/dist/ui/theme-inline.css +44 -0
- package/dist/ui/theme.css +103 -76
- package/dist/{ui-aMoA-9nq.mjs → ui-COLWzDsu.mjs} +6024 -3004
- package/dist/vanilla/adapters/index.d.mts +3 -3
- package/dist/vanilla/adapters/index.mjs +2 -1
- package/dist/vanilla/index.d.mts +3 -3
- package/dist/vanilla/index.mjs +2 -1
- package/llms.txt +330 -0
- package/package.json +17 -10
- package/dist/better-auth-react-adapter-JoscqoDc.d.mts +0 -722
- package/dist/better-auth-types-CE4hLv9E.d.mts +0 -9
- package/dist/supabase-adapter-Clxlqg1x.d.mts +0 -127
- /package/dist/{adapters-D0mxG3F-.mjs → adapters-B7YKkjaL.mjs} +0 -0
- /package/dist/{adapters-Df6Dd3KK.mjs → adapters-CivF9wql.mjs} +0 -0
- /package/dist/{index-ClXLQ1fw.d.mts → index-CPnFzULh.d.mts} +0 -0
- /package/dist/{index-BXlAjlSt.d.mts → index-CzsGMS7C.d.mts} +0 -0
- /package/dist/{index-DCQ5Y2ED.d.mts → index-OEBbnNdr.d.mts} +0 -0
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
import "../../adapter-core-CnrOXh1T.mjs";
|
|
2
|
+
import "../../better-auth-react-adapter-DNi5PC5D.mjs";
|
|
3
|
+
import "../../supabase-adapter-DUqw2fw8.mjs";
|
|
4
|
+
import { o as VanillaBetterAuthClient } from "../../neon-auth-BEGCfAe6.mjs";
|
|
5
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
6
|
+
|
|
7
|
+
//#region src/server/config.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Framework-agnostic configuration types for Neon Auth
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Session cookie configuration
|
|
13
|
+
*/
|
|
14
|
+
interface SessionCookieConfig {
|
|
15
|
+
/**
|
|
16
|
+
* Secret for signing session data cookies (enables session caching)
|
|
17
|
+
* Must be at least 32 characters for security.
|
|
18
|
+
*
|
|
19
|
+
* Generate a secure secret:
|
|
20
|
+
* ```bash
|
|
21
|
+
* openssl rand -base64 32
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @example process.env.NEON_AUTH_COOKIE_SECRET
|
|
25
|
+
*/
|
|
26
|
+
secret: string;
|
|
27
|
+
/**
|
|
28
|
+
* Time-to-live for cached session data in seconds
|
|
29
|
+
*
|
|
30
|
+
* Controls how long session data is cached in a signed cookie before
|
|
31
|
+
* requiring re-validation with the upstream auth server.
|
|
32
|
+
* Note: this does not affect the session token cookie TTL.
|
|
33
|
+
*
|
|
34
|
+
* @default 300 (5 minutes)
|
|
35
|
+
* @example 60 // Cache for 1 minute
|
|
36
|
+
* @example 600 // Cache for 10 minutes
|
|
37
|
+
*/
|
|
38
|
+
sessionDataTtl?: number;
|
|
39
|
+
/**
|
|
40
|
+
* Cookie domain for all Neon Auth cookies
|
|
41
|
+
*
|
|
42
|
+
* @default undefined (browser default - current domain only)
|
|
43
|
+
* @example '.example.com' // Share across subdomains
|
|
44
|
+
*/
|
|
45
|
+
domain?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Base configuration for Neon Auth server utilities
|
|
49
|
+
*/
|
|
50
|
+
interface NeonAuthConfig {
|
|
51
|
+
/**
|
|
52
|
+
* Base URL for the Neon Auth server
|
|
53
|
+
* @example 'https://ep-xxxx.neonauth.us-east-1.aws.neon.tech'
|
|
54
|
+
*/
|
|
55
|
+
baseUrl: string;
|
|
56
|
+
/**
|
|
57
|
+
* Cookie configuration
|
|
58
|
+
*/
|
|
59
|
+
cookies: SessionCookieConfig;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Configuration for Neon Auth middleware
|
|
63
|
+
* Extends base config with middleware-specific options
|
|
64
|
+
*/
|
|
65
|
+
interface NeonAuthMiddlewareConfig extends NeonAuthConfig {
|
|
66
|
+
/**
|
|
67
|
+
* URL to redirect to when user is not authenticated
|
|
68
|
+
* @default '/auth/sign-in'
|
|
69
|
+
*/
|
|
70
|
+
loginUrl?: string;
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/next/server/handler.d.ts
|
|
74
|
+
type Params = {
|
|
75
|
+
path: string[];
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* An API route handler to handle the auth requests from the client and proxy them to the Neon Auth.
|
|
79
|
+
*
|
|
80
|
+
* @param config - Required configuration
|
|
81
|
+
* @param config.baseUrl - Base URL of your Neon Auth instance
|
|
82
|
+
* @param config.cookies - Cookie configuration
|
|
83
|
+
* @param config.cookies.secret - Secret for signing session cookies (minimum 32 characters)
|
|
84
|
+
* @param config.cookies.sessionDataTtl - Optional TTL for session cache in seconds (default: 300)
|
|
85
|
+
* @returns A Next.js API handler functions that can be used in a Next.js route.
|
|
86
|
+
* @throws Error if `cookies.secret` is less than 32 characters
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* Mount the `authApiHandler` to an API route. Create a route file inside `/api/auth/[...all]/route.ts` directory.
|
|
90
|
+
* And add the following code:
|
|
91
|
+
*
|
|
92
|
+
* ```ts
|
|
93
|
+
* // app/api/auth/[...all]/route.ts
|
|
94
|
+
* import { authApiHandler } from '@neondatabase/auth/next';
|
|
95
|
+
*
|
|
96
|
+
* export const { GET, POST } = authApiHandler({
|
|
97
|
+
* baseUrl: process.env.NEON_AUTH_BASE_URL!,
|
|
98
|
+
* cookies: {
|
|
99
|
+
* secret: process.env.NEON_AUTH_COOKIE_SECRET!,
|
|
100
|
+
* },
|
|
101
|
+
* });
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
declare function authApiHandler(config: NeonAuthConfig): {
|
|
105
|
+
GET: (request: Request, {
|
|
106
|
+
params
|
|
107
|
+
}: {
|
|
108
|
+
params: Promise<Params>;
|
|
109
|
+
}) => Promise<Response>;
|
|
110
|
+
POST: (request: Request, {
|
|
111
|
+
params
|
|
112
|
+
}: {
|
|
113
|
+
params: Promise<Params>;
|
|
114
|
+
}) => Promise<Response>;
|
|
115
|
+
PUT: (request: Request, {
|
|
116
|
+
params
|
|
117
|
+
}: {
|
|
118
|
+
params: Promise<Params>;
|
|
119
|
+
}) => Promise<Response>;
|
|
120
|
+
DELETE: (request: Request, {
|
|
121
|
+
params
|
|
122
|
+
}: {
|
|
123
|
+
params: Promise<Params>;
|
|
124
|
+
}) => Promise<Response>;
|
|
125
|
+
PATCH: (request: Request, {
|
|
126
|
+
params
|
|
127
|
+
}: {
|
|
128
|
+
params: Promise<Params>;
|
|
129
|
+
}) => Promise<Response>;
|
|
130
|
+
};
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/next/server/middleware.d.ts
|
|
133
|
+
/**
|
|
134
|
+
* A Next.js middleware to protect routes from unauthenticated requests and refresh the session if required.
|
|
135
|
+
*
|
|
136
|
+
* @param config - Required middleware configuration
|
|
137
|
+
* @param config.baseUrl - Base URL of your Neon Auth instance
|
|
138
|
+
* @param config.cookies - Cookie configuration
|
|
139
|
+
* @param config.cookies.secret - Secret for signing session cookies (minimum 32 characters)
|
|
140
|
+
* @param config.cookies.sessionDataTtl - Optional TTL for session cache in seconds (default: 300)
|
|
141
|
+
* @param config.loginUrl - The URL to redirect to when the user is not authenticated (default: '/auth/sign-in')
|
|
142
|
+
* @returns A middleware function that can be used in the Next.js app.
|
|
143
|
+
* @throws Error if `cookies.secret` is less than 32 characters
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* import { neonAuthMiddleware } from "@neondatabase/auth/next"
|
|
148
|
+
*
|
|
149
|
+
* export default neonAuthMiddleware({
|
|
150
|
+
* baseUrl: process.env.NEON_AUTH_BASE_URL!,
|
|
151
|
+
* cookies: {
|
|
152
|
+
* secret: process.env.NEON_AUTH_COOKIE_SECRET!,
|
|
153
|
+
* },
|
|
154
|
+
* loginUrl: '/auth/sign-in',
|
|
155
|
+
* });
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
declare function neonAuthMiddleware(config: NeonAuthMiddlewareConfig): (request: NextRequest) => Promise<NextResponse<unknown>>;
|
|
159
|
+
//#endregion
|
|
160
|
+
//#region src/server/endpoints.d.ts
|
|
161
|
+
declare const API_ENDPOINTS: {
|
|
162
|
+
readonly getSession: {
|
|
163
|
+
readonly path: "get-session";
|
|
164
|
+
readonly method: "GET";
|
|
165
|
+
};
|
|
166
|
+
readonly getAccessToken: {
|
|
167
|
+
readonly path: "get-access-token";
|
|
168
|
+
readonly method: "GET";
|
|
169
|
+
};
|
|
170
|
+
readonly listSessions: {
|
|
171
|
+
readonly path: "list-sessions";
|
|
172
|
+
readonly method: "GET";
|
|
173
|
+
};
|
|
174
|
+
readonly revokeSession: {
|
|
175
|
+
readonly path: "revoke-session";
|
|
176
|
+
readonly method: "POST";
|
|
177
|
+
};
|
|
178
|
+
readonly revokeSessions: {
|
|
179
|
+
readonly path: "revoke-sessions";
|
|
180
|
+
readonly method: "POST";
|
|
181
|
+
};
|
|
182
|
+
readonly revokeOtherSessions: {
|
|
183
|
+
readonly path: "revoke-all-sessions";
|
|
184
|
+
readonly method: "POST";
|
|
185
|
+
};
|
|
186
|
+
readonly refreshToken: {
|
|
187
|
+
readonly path: "refresh-token";
|
|
188
|
+
readonly method: "POST";
|
|
189
|
+
};
|
|
190
|
+
readonly signIn: {
|
|
191
|
+
readonly email: {
|
|
192
|
+
readonly path: "sign-in/email";
|
|
193
|
+
readonly method: "POST";
|
|
194
|
+
};
|
|
195
|
+
readonly social: {
|
|
196
|
+
readonly path: "sign-in/social";
|
|
197
|
+
readonly method: "POST";
|
|
198
|
+
};
|
|
199
|
+
readonly emailOtp: {
|
|
200
|
+
readonly path: "sign-in/email-otp";
|
|
201
|
+
readonly method: "POST";
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
readonly signUp: {
|
|
205
|
+
readonly email: {
|
|
206
|
+
readonly path: "sign-up/email";
|
|
207
|
+
readonly method: "POST";
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
readonly signOut: {
|
|
211
|
+
readonly path: "sign-out";
|
|
212
|
+
readonly method: "POST";
|
|
213
|
+
};
|
|
214
|
+
readonly listAccounts: {
|
|
215
|
+
readonly path: "list-accounts";
|
|
216
|
+
readonly method: "GET";
|
|
217
|
+
};
|
|
218
|
+
readonly accountInfo: {
|
|
219
|
+
readonly path: "account-info";
|
|
220
|
+
readonly method: "GET";
|
|
221
|
+
};
|
|
222
|
+
readonly updateUser: {
|
|
223
|
+
readonly path: "update-user";
|
|
224
|
+
readonly method: "POST";
|
|
225
|
+
};
|
|
226
|
+
readonly deleteUser: {
|
|
227
|
+
readonly path: "delete-user";
|
|
228
|
+
readonly method: "POST";
|
|
229
|
+
};
|
|
230
|
+
readonly changePassword: {
|
|
231
|
+
readonly path: "change-password";
|
|
232
|
+
readonly method: "POST";
|
|
233
|
+
};
|
|
234
|
+
readonly sendVerificationEmail: {
|
|
235
|
+
readonly path: "send-verification-email";
|
|
236
|
+
readonly method: "POST";
|
|
237
|
+
};
|
|
238
|
+
readonly verifyEmail: {
|
|
239
|
+
readonly path: "verify-email";
|
|
240
|
+
readonly method: "POST";
|
|
241
|
+
};
|
|
242
|
+
readonly resetPassword: {
|
|
243
|
+
readonly path: "reset-password";
|
|
244
|
+
readonly method: "POST";
|
|
245
|
+
};
|
|
246
|
+
readonly requestPasswordReset: {
|
|
247
|
+
readonly path: "request-password-reset";
|
|
248
|
+
readonly method: "POST";
|
|
249
|
+
};
|
|
250
|
+
readonly token: {
|
|
251
|
+
readonly path: "token";
|
|
252
|
+
readonly method: "GET";
|
|
253
|
+
};
|
|
254
|
+
readonly jwks: {
|
|
255
|
+
readonly path: "jwt";
|
|
256
|
+
readonly method: "GET";
|
|
257
|
+
};
|
|
258
|
+
readonly getAnonymousToken: {
|
|
259
|
+
readonly path: "token/anonymous";
|
|
260
|
+
readonly method: "GET";
|
|
261
|
+
};
|
|
262
|
+
readonly admin: {
|
|
263
|
+
readonly createUser: {
|
|
264
|
+
readonly path: "admin/create-user";
|
|
265
|
+
readonly method: "POST";
|
|
266
|
+
};
|
|
267
|
+
readonly listUsers: {
|
|
268
|
+
readonly path: "admin/list-users";
|
|
269
|
+
readonly method: "GET";
|
|
270
|
+
};
|
|
271
|
+
readonly setRole: {
|
|
272
|
+
readonly path: "admin/set-role";
|
|
273
|
+
readonly method: "POST";
|
|
274
|
+
};
|
|
275
|
+
readonly setUserPassword: {
|
|
276
|
+
readonly path: "admin/set-user-password";
|
|
277
|
+
readonly method: "POST";
|
|
278
|
+
};
|
|
279
|
+
readonly updateUser: {
|
|
280
|
+
readonly path: "admin/update-user";
|
|
281
|
+
readonly method: "POST";
|
|
282
|
+
};
|
|
283
|
+
readonly banUser: {
|
|
284
|
+
readonly path: "admin/ban-user";
|
|
285
|
+
readonly method: "POST";
|
|
286
|
+
};
|
|
287
|
+
readonly unbanUser: {
|
|
288
|
+
readonly path: "admin/unban-user";
|
|
289
|
+
readonly method: "POST";
|
|
290
|
+
};
|
|
291
|
+
readonly listUserSessions: {
|
|
292
|
+
readonly path: "admin/list-user-sessions";
|
|
293
|
+
readonly method: "GET";
|
|
294
|
+
};
|
|
295
|
+
readonly revokeUserSession: {
|
|
296
|
+
readonly path: "admin/revoke-user-session";
|
|
297
|
+
readonly method: "POST";
|
|
298
|
+
};
|
|
299
|
+
readonly revokeUserSessions: {
|
|
300
|
+
readonly path: "admin/revoke-user-sessions";
|
|
301
|
+
readonly method: "POST";
|
|
302
|
+
};
|
|
303
|
+
readonly impersonateUser: {
|
|
304
|
+
readonly path: "admin/impersonate-user";
|
|
305
|
+
readonly method: "POST";
|
|
306
|
+
};
|
|
307
|
+
readonly stopImpersonating: {
|
|
308
|
+
readonly path: "admin/stop-impersonating";
|
|
309
|
+
readonly method: "POST";
|
|
310
|
+
};
|
|
311
|
+
readonly removeUser: {
|
|
312
|
+
readonly path: "admin/remove-user";
|
|
313
|
+
readonly method: "POST";
|
|
314
|
+
};
|
|
315
|
+
readonly hasPermission: {
|
|
316
|
+
readonly path: "admin/has-permission";
|
|
317
|
+
readonly method: "POST";
|
|
318
|
+
};
|
|
319
|
+
};
|
|
320
|
+
readonly organization: {
|
|
321
|
+
readonly create: {
|
|
322
|
+
readonly path: "organization/create";
|
|
323
|
+
readonly method: "POST";
|
|
324
|
+
};
|
|
325
|
+
readonly update: {
|
|
326
|
+
readonly path: "organization/update";
|
|
327
|
+
readonly method: "POST";
|
|
328
|
+
};
|
|
329
|
+
readonly delete: {
|
|
330
|
+
readonly path: "organization/delete";
|
|
331
|
+
readonly method: "POST";
|
|
332
|
+
};
|
|
333
|
+
readonly list: {
|
|
334
|
+
readonly path: "organization/list";
|
|
335
|
+
readonly method: "GET";
|
|
336
|
+
};
|
|
337
|
+
readonly getFullOrganization: {
|
|
338
|
+
readonly path: "organization/get-full-organization";
|
|
339
|
+
readonly method: "GET";
|
|
340
|
+
};
|
|
341
|
+
readonly setActive: {
|
|
342
|
+
readonly path: "organization/set-active";
|
|
343
|
+
readonly method: "POST";
|
|
344
|
+
};
|
|
345
|
+
readonly checkSlug: {
|
|
346
|
+
readonly path: "organization/check-slug";
|
|
347
|
+
readonly method: "GET";
|
|
348
|
+
};
|
|
349
|
+
readonly listMembers: {
|
|
350
|
+
readonly path: "organization/list-members";
|
|
351
|
+
readonly method: "GET";
|
|
352
|
+
};
|
|
353
|
+
readonly removeMember: {
|
|
354
|
+
readonly path: "organization/remove-member";
|
|
355
|
+
readonly method: "POST";
|
|
356
|
+
};
|
|
357
|
+
readonly updateMemberRole: {
|
|
358
|
+
readonly path: "organization/update-member-role";
|
|
359
|
+
readonly method: "POST";
|
|
360
|
+
};
|
|
361
|
+
readonly leave: {
|
|
362
|
+
readonly path: "organization/leave";
|
|
363
|
+
readonly method: "POST";
|
|
364
|
+
};
|
|
365
|
+
readonly getActiveMember: {
|
|
366
|
+
readonly path: "organization/get-active-member";
|
|
367
|
+
readonly method: "GET";
|
|
368
|
+
};
|
|
369
|
+
readonly getActiveMemberRole: {
|
|
370
|
+
readonly path: "organization/get-active-member-role";
|
|
371
|
+
readonly method: "GET";
|
|
372
|
+
};
|
|
373
|
+
readonly inviteMember: {
|
|
374
|
+
readonly path: "organization/invite-member";
|
|
375
|
+
readonly method: "POST";
|
|
376
|
+
};
|
|
377
|
+
readonly acceptInvitation: {
|
|
378
|
+
readonly path: "organization/accept-invitation";
|
|
379
|
+
readonly method: "POST";
|
|
380
|
+
};
|
|
381
|
+
readonly rejectInvitation: {
|
|
382
|
+
readonly path: "organization/reject-invitation";
|
|
383
|
+
readonly method: "POST";
|
|
384
|
+
};
|
|
385
|
+
readonly cancelInvitation: {
|
|
386
|
+
readonly path: "organization/cancel-invitation";
|
|
387
|
+
readonly method: "POST";
|
|
388
|
+
};
|
|
389
|
+
readonly getInvitation: {
|
|
390
|
+
readonly path: "organization/get-invitation";
|
|
391
|
+
readonly method: "GET";
|
|
392
|
+
};
|
|
393
|
+
readonly listInvitations: {
|
|
394
|
+
readonly path: "organization/list-invitations";
|
|
395
|
+
readonly method: "GET";
|
|
396
|
+
};
|
|
397
|
+
readonly listUserInvitations: {
|
|
398
|
+
readonly path: "organization/list-user-invitations";
|
|
399
|
+
readonly method: "GET";
|
|
400
|
+
};
|
|
401
|
+
readonly hasPermission: {
|
|
402
|
+
readonly path: "organization/has-permission";
|
|
403
|
+
readonly method: "POST";
|
|
404
|
+
};
|
|
405
|
+
};
|
|
406
|
+
readonly emailOtp: {
|
|
407
|
+
readonly sendVerificationOtp: {
|
|
408
|
+
readonly path: "email-otp/send-verification-otp";
|
|
409
|
+
readonly method: "POST";
|
|
410
|
+
};
|
|
411
|
+
readonly verifyEmail: {
|
|
412
|
+
readonly path: "email-otp/verify-email";
|
|
413
|
+
readonly method: "POST";
|
|
414
|
+
};
|
|
415
|
+
readonly checkVerificationOtp: {
|
|
416
|
+
readonly path: "email-otp/check-verification-otp";
|
|
417
|
+
readonly method: "POST";
|
|
418
|
+
};
|
|
419
|
+
readonly resetPassword: {
|
|
420
|
+
readonly path: "email-otp/passcode";
|
|
421
|
+
readonly method: "POST";
|
|
422
|
+
};
|
|
423
|
+
};
|
|
424
|
+
};
|
|
425
|
+
//#endregion
|
|
426
|
+
//#region src/server/types.d.ts
|
|
427
|
+
/**
|
|
428
|
+
* Extract top-level keys from API_ENDPOINTS.
|
|
429
|
+
* For nested endpoints like signIn.email, this extracts 'signIn' (not 'email').
|
|
430
|
+
*/
|
|
431
|
+
type TopLevelEndpointKeys<T> = { [K in keyof T]: K }[keyof T];
|
|
432
|
+
type ServerAuthMethods = TopLevelEndpointKeys<typeof API_ENDPOINTS>;
|
|
433
|
+
type NeonAuthServer = Pick<VanillaBetterAuthClient, ServerAuthMethods>;
|
|
434
|
+
//#endregion
|
|
435
|
+
//#region src/next/server/index.d.ts
|
|
436
|
+
/**
|
|
437
|
+
* Unified entry point for Neon Auth in Next.js
|
|
438
|
+
*
|
|
439
|
+
* This is the recommended way to use Neon Auth in Next.js. It provides a single
|
|
440
|
+
* entry point that combines all server-side functionality.
|
|
441
|
+
*
|
|
442
|
+
* **Features:**
|
|
443
|
+
* - All Better Auth server methods (signIn, signUp, getSession, etc.)
|
|
444
|
+
* - `.handler()` - API route handler for `/api/auth/[...path]`
|
|
445
|
+
* - `.middleware(config?)` - Middleware for route protection
|
|
446
|
+
*
|
|
447
|
+
* **Where to use:**
|
|
448
|
+
* - React Server Components
|
|
449
|
+
* - Server Actions
|
|
450
|
+
* - Route Handlers
|
|
451
|
+
* - Middleware
|
|
452
|
+
*
|
|
453
|
+
* @param config - Required configuration
|
|
454
|
+
* @param config.baseUrl - Base URL of your Neon Auth instance
|
|
455
|
+
* @param config.cookies - Cookie configuration
|
|
456
|
+
* @param config.cookies.secret - Secret for signing session cookies (minimum 32 characters)
|
|
457
|
+
* @param config.cookies.sessionDataTtl - Optional TTL for session cache in seconds (default: 300)
|
|
458
|
+
* @param config.cookies.domain - Optional cookie domain (default: current domain)
|
|
459
|
+
* @returns Unified auth instance with server methods, handler, and middleware
|
|
460
|
+
* @throws Error if `cookies.secret` is less than 32 characters
|
|
461
|
+
*
|
|
462
|
+
* @example
|
|
463
|
+
* ```typescript
|
|
464
|
+
* // lib/auth.ts - Create a singleton instance
|
|
465
|
+
* import { createNeonAuth } from '@neondatabase/auth/next/server';
|
|
466
|
+
*
|
|
467
|
+
* export const auth = createNeonAuth({
|
|
468
|
+
* baseUrl: process.env.NEON_AUTH_BASE_URL!,
|
|
469
|
+
* cookies: {
|
|
470
|
+
* secret: process.env.NEON_AUTH_COOKIE_SECRET!,
|
|
471
|
+
* sessionDataTtl: 300, // 5 minutes (default)
|
|
472
|
+
* },
|
|
473
|
+
* });
|
|
474
|
+
* ```
|
|
475
|
+
*
|
|
476
|
+
* @example
|
|
477
|
+
* ```typescript
|
|
478
|
+
* // app/api/auth/[...path]/route.ts - API handler
|
|
479
|
+
* import { auth } from '@/lib/auth';
|
|
480
|
+
*
|
|
481
|
+
* export const { GET, POST } = auth.handler();
|
|
482
|
+
* ```
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* ```typescript
|
|
486
|
+
* // middleware.ts - Route protection
|
|
487
|
+
* import { auth } from '@/lib/auth';
|
|
488
|
+
*
|
|
489
|
+
* export default auth.middleware({ loginUrl: '/auth/sign-in' });
|
|
490
|
+
*
|
|
491
|
+
* export const config = {
|
|
492
|
+
* matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
|
|
493
|
+
* };
|
|
494
|
+
* ```
|
|
495
|
+
*
|
|
496
|
+
* @example
|
|
497
|
+
* ```typescript
|
|
498
|
+
* // app/page.tsx - Server Component
|
|
499
|
+
* import { auth } from '@/lib/auth';
|
|
500
|
+
*
|
|
501
|
+
* // Server components using `auth` methods must be rendered dynamically
|
|
502
|
+
* export const dynamic = 'force-dynamic'
|
|
503
|
+
*
|
|
504
|
+
* export default async function Page() {
|
|
505
|
+
* const { data: session } = await auth.getSession();
|
|
506
|
+
* if (!session?.user) return <div>Not logged in</div>;
|
|
507
|
+
* return <div>Hello {session.user.name}</div>;
|
|
508
|
+
* }
|
|
509
|
+
* ```
|
|
510
|
+
*
|
|
511
|
+
* @example
|
|
512
|
+
* ```typescript
|
|
513
|
+
* // app/actions.ts - Server Action
|
|
514
|
+
* 'use server';
|
|
515
|
+
* import { auth } from '@/lib/auth';
|
|
516
|
+
* import { redirect } from 'next/navigation';
|
|
517
|
+
*
|
|
518
|
+
* export async function signIn(formData: FormData) {
|
|
519
|
+
* const { error } = await auth.signIn.email({
|
|
520
|
+
* email: formData.get('email') as string,
|
|
521
|
+
* password: formData.get('password') as string,
|
|
522
|
+
* });
|
|
523
|
+
* if (error) return { error: error.message };
|
|
524
|
+
* redirect('/dashboard');
|
|
525
|
+
* }
|
|
526
|
+
* ```
|
|
527
|
+
*/
|
|
528
|
+
declare function createNeonAuth(config: NeonAuthConfig): NeonAuth;
|
|
529
|
+
/**
|
|
530
|
+
* Return type for createNeonAuth
|
|
531
|
+
* Includes all Better Auth server methods plus handler() and middleware()
|
|
532
|
+
*/
|
|
533
|
+
type NeonAuth = NeonAuthServer & {
|
|
534
|
+
handler: () => ReturnType<typeof authApiHandler>;
|
|
535
|
+
middleware: (middlewareConfig?: Pick<NeonAuthMiddlewareConfig, 'loginUrl'>) => ReturnType<typeof neonAuthMiddleware>;
|
|
536
|
+
};
|
|
537
|
+
//#endregion
|
|
538
|
+
export { NeonAuth, createNeonAuth };
|