@farm.js/auth 0.1.1-beta.2 → 0.1.1-beta.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm.js/auth",
3
- "version": "0.1.1-beta.2",
3
+ "version": "0.1.1-beta.3",
4
4
  "description": "Farm-native authentication with email/password, server helpers, and React hooks",
5
5
  "license": "MIT",
6
6
  "repository": {
package/dist/client.d.ts DELETED
@@ -1,539 +0,0 @@
1
- import type { FarmAuthClientOptions, FarmAuthCredentials, FarmAuthSignUpInput } from "./types.js";
2
- export declare function createFarmAuthClient(options?: FarmAuthClientOptions): {
3
- signIn: (input: FarmAuthCredentials) => Promise<{
4
- data: Omit<{
5
- redirect: boolean;
6
- token: string;
7
- url?: string | undefined;
8
- user: {
9
- id: string;
10
- createdAt: Date;
11
- updatedAt: Date;
12
- email: string;
13
- emailVerified: boolean;
14
- name: string;
15
- image?: string | null | undefined | undefined;
16
- };
17
- }, "user"> & {
18
- user: import("better-auth").StripEmptyObjects<{
19
- id: string;
20
- createdAt: Date;
21
- updatedAt: Date;
22
- email: string;
23
- emailVerified: boolean;
24
- name: string;
25
- image?: string | null | undefined;
26
- }>;
27
- };
28
- error: null;
29
- } | {
30
- data: null;
31
- error: {
32
- code?: string | undefined | undefined;
33
- message?: string | undefined | undefined;
34
- status: number;
35
- statusText: string;
36
- };
37
- }>;
38
- signUp: (input: FarmAuthSignUpInput) => Promise<{
39
- data: (Omit<{
40
- token: null;
41
- user: {
42
- id: string;
43
- createdAt: Date;
44
- updatedAt: Date;
45
- email: string;
46
- emailVerified: boolean;
47
- name: string;
48
- image?: string | null | undefined | undefined;
49
- };
50
- }, "user"> & {
51
- user: import("better-auth").StripEmptyObjects<{
52
- id: string;
53
- createdAt: Date;
54
- updatedAt: Date;
55
- email: string;
56
- emailVerified: boolean;
57
- name: string;
58
- image?: string | null | undefined;
59
- }>;
60
- }) | (Omit<{
61
- token: string;
62
- user: {
63
- id: string;
64
- createdAt: Date;
65
- updatedAt: Date;
66
- email: string;
67
- emailVerified: boolean;
68
- name: string;
69
- image?: string | null | undefined | undefined;
70
- };
71
- }, "user"> & {
72
- user: import("better-auth").StripEmptyObjects<{
73
- id: string;
74
- createdAt: Date;
75
- updatedAt: Date;
76
- email: string;
77
- emailVerified: boolean;
78
- name: string;
79
- image?: string | null | undefined;
80
- }>;
81
- });
82
- error: null;
83
- } | {
84
- data: null;
85
- error: {
86
- code?: string | undefined | undefined;
87
- message?: string | undefined | undefined;
88
- status: number;
89
- statusText: string;
90
- };
91
- }>;
92
- signOut: () => Promise<{
93
- data: {
94
- success: boolean;
95
- url: string | undefined;
96
- redirect: boolean | undefined;
97
- };
98
- error: null;
99
- } | {
100
- data: null;
101
- error: {
102
- code?: string | undefined | undefined;
103
- message?: string | undefined | undefined;
104
- status: number;
105
- statusText: string;
106
- };
107
- }>;
108
- getSession: () => Promise<{
109
- data: {
110
- user: import("better-auth").StripEmptyObjects<{
111
- id: string;
112
- createdAt: Date;
113
- updatedAt: Date;
114
- email: string;
115
- emailVerified: boolean;
116
- name: string;
117
- image?: string | null | undefined;
118
- }>;
119
- session: import("better-auth").StripEmptyObjects<{
120
- id: string;
121
- createdAt: Date;
122
- updatedAt: Date;
123
- userId: string;
124
- expiresAt: Date;
125
- token: string;
126
- ipAddress?: string | null | undefined;
127
- userAgent?: string | null | undefined;
128
- }>;
129
- } | null;
130
- error: null;
131
- } | {
132
- data: null;
133
- error: {
134
- code?: string | undefined | undefined;
135
- message?: string | undefined | undefined;
136
- status: number;
137
- statusText: string;
138
- };
139
- }>;
140
- useAuth: () => {
141
- user: import("better-auth").StripEmptyObjects<{
142
- id: string;
143
- createdAt: Date;
144
- updatedAt: Date;
145
- email: string;
146
- emailVerified: boolean;
147
- name: string;
148
- image?: string | null | undefined;
149
- }> | null;
150
- session: import("better-auth").StripEmptyObjects<{
151
- id: string;
152
- createdAt: Date;
153
- updatedAt: Date;
154
- userId: string;
155
- expiresAt: Date;
156
- token: string;
157
- ipAddress?: string | null | undefined;
158
- userAgent?: string | null | undefined;
159
- }> | null;
160
- isPending: boolean;
161
- isRefetching: boolean;
162
- error: import("better-auth/react").BetterFetchError | null;
163
- refetch: (queryParams?: {
164
- query?: import("better-auth").SessionQueryParams;
165
- } | undefined) => Promise<void>;
166
- signIn: (input: FarmAuthCredentials) => Promise<{
167
- data: Omit<{
168
- redirect: boolean;
169
- token: string;
170
- url?: string | undefined;
171
- user: {
172
- id: string;
173
- createdAt: Date;
174
- updatedAt: Date;
175
- email: string;
176
- emailVerified: boolean;
177
- name: string;
178
- image?: string | null | undefined | undefined;
179
- };
180
- }, "user"> & {
181
- user: import("better-auth").StripEmptyObjects<{
182
- id: string;
183
- createdAt: Date;
184
- updatedAt: Date;
185
- email: string;
186
- emailVerified: boolean;
187
- name: string;
188
- image?: string | null | undefined;
189
- }>;
190
- };
191
- error: null;
192
- } | {
193
- data: null;
194
- error: {
195
- code?: string | undefined | undefined;
196
- message?: string | undefined | undefined;
197
- status: number;
198
- statusText: string;
199
- };
200
- }>;
201
- signUp: (input: FarmAuthSignUpInput) => Promise<{
202
- data: (Omit<{
203
- token: null;
204
- user: {
205
- id: string;
206
- createdAt: Date;
207
- updatedAt: Date;
208
- email: string;
209
- emailVerified: boolean;
210
- name: string;
211
- image?: string | null | undefined | undefined;
212
- };
213
- }, "user"> & {
214
- user: import("better-auth").StripEmptyObjects<{
215
- id: string;
216
- createdAt: Date;
217
- updatedAt: Date;
218
- email: string;
219
- emailVerified: boolean;
220
- name: string;
221
- image?: string | null | undefined;
222
- }>;
223
- }) | (Omit<{
224
- token: string;
225
- user: {
226
- id: string;
227
- createdAt: Date;
228
- updatedAt: Date;
229
- email: string;
230
- emailVerified: boolean;
231
- name: string;
232
- image?: string | null | undefined | undefined;
233
- };
234
- }, "user"> & {
235
- user: import("better-auth").StripEmptyObjects<{
236
- id: string;
237
- createdAt: Date;
238
- updatedAt: Date;
239
- email: string;
240
- emailVerified: boolean;
241
- name: string;
242
- image?: string | null | undefined;
243
- }>;
244
- });
245
- error: null;
246
- } | {
247
- data: null;
248
- error: {
249
- code?: string | undefined | undefined;
250
- message?: string | undefined | undefined;
251
- status: number;
252
- statusText: string;
253
- };
254
- }>;
255
- signOut: () => Promise<{
256
- data: {
257
- success: boolean;
258
- url: string | undefined;
259
- redirect: boolean | undefined;
260
- };
261
- error: null;
262
- } | {
263
- data: null;
264
- error: {
265
- code?: string | undefined | undefined;
266
- message?: string | undefined | undefined;
267
- status: number;
268
- statusText: string;
269
- };
270
- }>;
271
- };
272
- };
273
- export declare const getSession: () => Promise<{
274
- data: {
275
- user: import("better-auth").StripEmptyObjects<{
276
- id: string;
277
- createdAt: Date;
278
- updatedAt: Date;
279
- email: string;
280
- emailVerified: boolean;
281
- name: string;
282
- image?: string | null | undefined;
283
- }>;
284
- session: import("better-auth").StripEmptyObjects<{
285
- id: string;
286
- createdAt: Date;
287
- updatedAt: Date;
288
- userId: string;
289
- expiresAt: Date;
290
- token: string;
291
- ipAddress?: string | null | undefined;
292
- userAgent?: string | null | undefined;
293
- }>;
294
- } | null;
295
- error: null;
296
- } | {
297
- data: null;
298
- error: {
299
- code?: string | undefined | undefined;
300
- message?: string | undefined | undefined;
301
- status: number;
302
- statusText: string;
303
- };
304
- }>, signIn: (input: FarmAuthCredentials) => Promise<{
305
- data: Omit<{
306
- redirect: boolean;
307
- token: string;
308
- url?: string | undefined;
309
- user: {
310
- id: string;
311
- createdAt: Date;
312
- updatedAt: Date;
313
- email: string;
314
- emailVerified: boolean;
315
- name: string;
316
- image?: string | null | undefined | undefined;
317
- };
318
- }, "user"> & {
319
- user: import("better-auth").StripEmptyObjects<{
320
- id: string;
321
- createdAt: Date;
322
- updatedAt: Date;
323
- email: string;
324
- emailVerified: boolean;
325
- name: string;
326
- image?: string | null | undefined;
327
- }>;
328
- };
329
- error: null;
330
- } | {
331
- data: null;
332
- error: {
333
- code?: string | undefined | undefined;
334
- message?: string | undefined | undefined;
335
- status: number;
336
- statusText: string;
337
- };
338
- }>, signOut: () => Promise<{
339
- data: {
340
- success: boolean;
341
- url: string | undefined;
342
- redirect: boolean | undefined;
343
- };
344
- error: null;
345
- } | {
346
- data: null;
347
- error: {
348
- code?: string | undefined | undefined;
349
- message?: string | undefined | undefined;
350
- status: number;
351
- statusText: string;
352
- };
353
- }>, signUp: (input: FarmAuthSignUpInput) => Promise<{
354
- data: (Omit<{
355
- token: null;
356
- user: {
357
- id: string;
358
- createdAt: Date;
359
- updatedAt: Date;
360
- email: string;
361
- emailVerified: boolean;
362
- name: string;
363
- image?: string | null | undefined | undefined;
364
- };
365
- }, "user"> & {
366
- user: import("better-auth").StripEmptyObjects<{
367
- id: string;
368
- createdAt: Date;
369
- updatedAt: Date;
370
- email: string;
371
- emailVerified: boolean;
372
- name: string;
373
- image?: string | null | undefined;
374
- }>;
375
- }) | (Omit<{
376
- token: string;
377
- user: {
378
- id: string;
379
- createdAt: Date;
380
- updatedAt: Date;
381
- email: string;
382
- emailVerified: boolean;
383
- name: string;
384
- image?: string | null | undefined | undefined;
385
- };
386
- }, "user"> & {
387
- user: import("better-auth").StripEmptyObjects<{
388
- id: string;
389
- createdAt: Date;
390
- updatedAt: Date;
391
- email: string;
392
- emailVerified: boolean;
393
- name: string;
394
- image?: string | null | undefined;
395
- }>;
396
- });
397
- error: null;
398
- } | {
399
- data: null;
400
- error: {
401
- code?: string | undefined | undefined;
402
- message?: string | undefined | undefined;
403
- status: number;
404
- statusText: string;
405
- };
406
- }>, useAuth: () => {
407
- user: import("better-auth").StripEmptyObjects<{
408
- id: string;
409
- createdAt: Date;
410
- updatedAt: Date;
411
- email: string;
412
- emailVerified: boolean;
413
- name: string;
414
- image?: string | null | undefined;
415
- }> | null;
416
- session: import("better-auth").StripEmptyObjects<{
417
- id: string;
418
- createdAt: Date;
419
- updatedAt: Date;
420
- userId: string;
421
- expiresAt: Date;
422
- token: string;
423
- ipAddress?: string | null | undefined;
424
- userAgent?: string | null | undefined;
425
- }> | null;
426
- isPending: boolean;
427
- isRefetching: boolean;
428
- error: import("better-auth/react").BetterFetchError | null;
429
- refetch: (queryParams?: {
430
- query?: import("better-auth").SessionQueryParams;
431
- } | undefined) => Promise<void>;
432
- signIn: (input: FarmAuthCredentials) => Promise<{
433
- data: Omit<{
434
- redirect: boolean;
435
- token: string;
436
- url?: string | undefined;
437
- user: {
438
- id: string;
439
- createdAt: Date;
440
- updatedAt: Date;
441
- email: string;
442
- emailVerified: boolean;
443
- name: string;
444
- image?: string | null | undefined | undefined;
445
- };
446
- }, "user"> & {
447
- user: import("better-auth").StripEmptyObjects<{
448
- id: string;
449
- createdAt: Date;
450
- updatedAt: Date;
451
- email: string;
452
- emailVerified: boolean;
453
- name: string;
454
- image?: string | null | undefined;
455
- }>;
456
- };
457
- error: null;
458
- } | {
459
- data: null;
460
- error: {
461
- code?: string | undefined | undefined;
462
- message?: string | undefined | undefined;
463
- status: number;
464
- statusText: string;
465
- };
466
- }>;
467
- signUp: (input: FarmAuthSignUpInput) => Promise<{
468
- data: (Omit<{
469
- token: null;
470
- user: {
471
- id: string;
472
- createdAt: Date;
473
- updatedAt: Date;
474
- email: string;
475
- emailVerified: boolean;
476
- name: string;
477
- image?: string | null | undefined | undefined;
478
- };
479
- }, "user"> & {
480
- user: import("better-auth").StripEmptyObjects<{
481
- id: string;
482
- createdAt: Date;
483
- updatedAt: Date;
484
- email: string;
485
- emailVerified: boolean;
486
- name: string;
487
- image?: string | null | undefined;
488
- }>;
489
- }) | (Omit<{
490
- token: string;
491
- user: {
492
- id: string;
493
- createdAt: Date;
494
- updatedAt: Date;
495
- email: string;
496
- emailVerified: boolean;
497
- name: string;
498
- image?: string | null | undefined | undefined;
499
- };
500
- }, "user"> & {
501
- user: import("better-auth").StripEmptyObjects<{
502
- id: string;
503
- createdAt: Date;
504
- updatedAt: Date;
505
- email: string;
506
- emailVerified: boolean;
507
- name: string;
508
- image?: string | null | undefined;
509
- }>;
510
- });
511
- error: null;
512
- } | {
513
- data: null;
514
- error: {
515
- code?: string | undefined | undefined;
516
- message?: string | undefined | undefined;
517
- status: number;
518
- statusText: string;
519
- };
520
- }>;
521
- signOut: () => Promise<{
522
- data: {
523
- success: boolean;
524
- url: string | undefined;
525
- redirect: boolean | undefined;
526
- };
527
- error: null;
528
- } | {
529
- data: null;
530
- error: {
531
- code?: string | undefined | undefined;
532
- message?: string | undefined | undefined;
533
- status: number;
534
- statusText: string;
535
- };
536
- }>;
537
- };
538
- export type { FarmAuthClientOptions, FarmAuthCredentials, FarmAuthSignUpInput } from "./types.js";
539
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAElG,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,qBAA0B;oBAG/C,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAInB,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0CilB,CAAC;;wBA9CrmB,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAInB,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmC3C;AAID,eAAO,MAAQ,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAE,MAAM,UA3CR,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA2CT,OAAO;;;;;;;;;;;;;;;IAAE,MAAM,UAvCzB,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAuCQ,OAAO;;;;;;;;;;;;;;;;;;;;;;;;aAGkkB,CAAC;;oBA9CrmB,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAInB,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuCiC,CAAC;AAE9E,YAAY,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC"}
package/dist/client.js DELETED
@@ -1,40 +0,0 @@
1
- "use client";
2
- import { createAuthClient } from "better-auth/react";
3
- export function createFarmAuthClient(options = {}) {
4
- const client = createAuthClient(options);
5
- function signIn(input) {
6
- return client.signIn.email(input);
7
- }
8
- function signUp(input) {
9
- return client.signUp.email(input);
10
- }
11
- function signOut() {
12
- return client.signOut();
13
- }
14
- function getSession() {
15
- return client.getSession();
16
- }
17
- function useAuth() {
18
- const state = client.useSession();
19
- return {
20
- user: state.data?.user ?? null,
21
- session: state.data?.session ?? null,
22
- isPending: state.isPending,
23
- isRefetching: state.isRefetching,
24
- error: state.error,
25
- refetch: state.refetch,
26
- signIn,
27
- signUp,
28
- signOut,
29
- };
30
- }
31
- return {
32
- signIn,
33
- signUp,
34
- signOut,
35
- getSession,
36
- useAuth,
37
- };
38
- }
39
- const defaultClient = createFarmAuthClient();
40
- export const { getSession, signIn, signOut, signUp, useAuth } = defaultClient;
package/dist/config.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import type { FarmAuthUserConfig, ResolvedFarmAuthConfig } from "./types.js";
2
- export declare function resolveFarmAuthConfig(input: FarmAuthUserConfig | undefined): ResolvedFarmAuthConfig;
3
- //# sourceMappingURL=config.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAK7E,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,kBAAkB,GAAG,SAAS,GACpC,sBAAsB,CAiDxB"}
package/dist/config.js DELETED
@@ -1,106 +0,0 @@
1
- const DEFAULT_SESSION_EXPIRES_IN = 60 * 60 * 24 * 7;
2
- const DEFAULT_SESSION_UPDATE_AGE = 60 * 60 * 24;
3
- export function resolveFarmAuthConfig(input) {
4
- if (input === false || input === undefined) {
5
- return {
6
- enabled: false,
7
- basePath: "/api/auth",
8
- emailAndPassword: {
9
- enabled: true,
10
- requireEmailVerification: false,
11
- minPasswordLength: 8,
12
- maxPasswordLength: 128,
13
- },
14
- session: {
15
- expiresIn: DEFAULT_SESSION_EXPIRES_IN,
16
- updateAge: DEFAULT_SESSION_UPDATE_AGE,
17
- },
18
- database: {
19
- path: ".farm/auth.sqlite",
20
- migrateInDevelopment: true,
21
- },
22
- };
23
- }
24
- const config = input === true ? {} : input;
25
- const passwordConfig = typeof config.emailAndPassword === "object" ? config.emailAndPassword : {};
26
- const basePath = normalizeBasePath(config.basePath);
27
- const resolved = {
28
- enabled: config.enabled !== false,
29
- appName: config.appName,
30
- basePath,
31
- emailAndPassword: {
32
- enabled: config.emailAndPassword !== false,
33
- requireEmailVerification: passwordConfig.requireEmailVerification ?? false,
34
- minPasswordLength: passwordConfig.minPasswordLength ?? 8,
35
- maxPasswordLength: passwordConfig.maxPasswordLength ?? 128,
36
- },
37
- session: {
38
- expiresIn: config.session?.expiresIn ?? DEFAULT_SESSION_EXPIRES_IN,
39
- updateAge: config.session?.updateAge ?? DEFAULT_SESSION_UPDATE_AGE,
40
- },
41
- database: {
42
- url: config.database?.url,
43
- path: config.database?.path || ".farm/auth.sqlite",
44
- migrateInDevelopment: config.database?.migrateInDevelopment ?? true,
45
- },
46
- };
47
- validateFarmAuthConfig(resolved);
48
- return resolved;
49
- }
50
- function normalizeBasePath(value) {
51
- const route = (value || "/api/auth").trim();
52
- if (!route)
53
- return "/api/auth";
54
- assertStableBasePath(route);
55
- const withLeadingSlash = route.startsWith("/") ? route : `/${route}`;
56
- const normalized = withLeadingSlash.replace(/\/+/g, "/").replace(/\/+$/, "");
57
- return normalized || "/api/auth";
58
- }
59
- function assertStableBasePath(route) {
60
- if (route.includes("?") || route.includes("#")) {
61
- throw new Error("auth.basePath cannot contain a query string or fragment.");
62
- }
63
- if (route.startsWith("//") || /^[a-z][a-z\d+.-]*:\/\//i.test(route)) {
64
- throw new Error('auth.basePath must be an application pathname such as "/api/auth".');
65
- }
66
- if (hasUnstablePathCharacters(route)) {
67
- throw new Error("auth.basePath cannot contain backslashes or control characters.");
68
- }
69
- for (const segment of route.split("/")) {
70
- let decoded = segment;
71
- try {
72
- decoded = decodeURIComponent(segment);
73
- }
74
- catch {
75
- // Malformed escapes remain literal URL pathname segments.
76
- }
77
- if (hasUnstablePathCharacters(decoded) || decoded.includes("/")) {
78
- throw new Error("auth.basePath cannot contain encoded path separators.");
79
- }
80
- if (decoded === "." || decoded === "..") {
81
- throw new Error('auth.basePath cannot contain "." or ".." path segments.');
82
- }
83
- }
84
- }
85
- function hasUnstablePathCharacters(value) {
86
- return (value.includes("\\") ||
87
- Array.from(value).some((character) => {
88
- const code = character.charCodeAt(0);
89
- return code <= 31 || (code >= 127 && code <= 159);
90
- }));
91
- }
92
- function validateFarmAuthConfig(config) {
93
- const { minPasswordLength, maxPasswordLength } = config.emailAndPassword;
94
- if (!Number.isInteger(minPasswordLength) || minPasswordLength < 1) {
95
- throw new Error("auth.emailAndPassword.minPasswordLength must be a positive integer.");
96
- }
97
- if (!Number.isInteger(maxPasswordLength) || maxPasswordLength < minPasswordLength) {
98
- throw new Error("auth.emailAndPassword.maxPasswordLength must be an integer greater than or equal to minPasswordLength.");
99
- }
100
- if (!Number.isInteger(config.session.expiresIn) || config.session.expiresIn < 1) {
101
- throw new Error("auth.session.expiresIn must be a positive integer.");
102
- }
103
- if (!Number.isInteger(config.session.updateAge) || config.session.updateAge < 0) {
104
- throw new Error("auth.session.updateAge must be a non-negative integer.");
105
- }
106
- }
package/dist/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export { resolveFarmAuthConfig } from "./config.js";
2
- export type { FarmAuthConfig, FarmAuthClientOptions, FarmAuthCredentials, FarmAuthDatabaseConfig, FarmAuthEmailAndPasswordConfig, FarmAuthSession, FarmAuthSessionConfig, FarmAuthSessionData, FarmAuthSignUpInput, FarmAuthUser, FarmAuthUserConfig, ResolvedFarmAuthConfig, } from "./types.js";
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,YAAY,EACV,cAAc,EACd,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,EACtB,8BAA8B,EAC9B,eAAe,EACf,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,EACZ,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,YAAY,CAAC"}
package/dist/index.js DELETED
@@ -1 +0,0 @@
1
- export { resolveFarmAuthConfig } from "./config.js";
@@ -1,24 +0,0 @@
1
- import type { ResolvedFarmAuthConfig } from "./types.js";
2
- interface FarmAuthIntegrationOptions {
3
- root: string;
4
- mode: "development" | "production";
5
- }
6
- interface FarmAuthIntegration {
7
- readonly kind: "farm-integration";
8
- category: "auth";
9
- type: "farm-auth";
10
- instance: {
11
- readonly kind: "farm-auth-runtime";
12
- };
13
- routes: Array<{
14
- path: string;
15
- methods: readonly ["GET", "POST"];
16
- handler(request: Request): Promise<Response>;
17
- }>;
18
- }
19
- export declare function createFarmAuthIntegration(config: ResolvedFarmAuthConfig, options: FarmAuthIntegrationOptions): FarmAuthIntegration;
20
- export declare function migrateFarmAuth(): Promise<void>;
21
- export declare function compileFarmAuthMigration(): Promise<string>;
22
- export declare function disposeFarmAuth(): Promise<void>;
23
- export {};
24
- //# sourceMappingURL=internal.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AASzD,UAAU,0BAA0B;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,aAAa,GAAG,YAAY,CAAC;CACpC;AAED,UAAU,mBAAmB;IAC3B,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,WAAW,CAAC;IAClB,QAAQ,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAA;KAAE,CAAC;IACjD,MAAM,EAAE,KAAK,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAClC,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;KAC9C,CAAC,CAAC;CACJ;AAED,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,sBAAsB,EAC9B,OAAO,EAAE,0BAA0B,GAClC,mBAAmB,CAmBrB;AAED,wBAAsB,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAErD;AAED,wBAAsB,wBAAwB,IAAI,OAAO,CAAC,MAAM,CAAC,CAEhE;AAED,wBAAsB,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAErD"}
package/dist/internal.js DELETED
@@ -1,29 +0,0 @@
1
- import { configureFarmAuth, disposeFarmAuth as runDispose, getFarmAuthRuntime, migrateFarmAuth as runMigration, compileFarmAuthMigration as runCompileMigration, } from "./runtime.js";
2
- export function createFarmAuthIntegration(config, options) {
3
- configureFarmAuth(config, options);
4
- return {
5
- kind: "farm-integration",
6
- category: "auth",
7
- type: "farm-auth",
8
- instance: Object.freeze({ kind: "farm-auth-runtime" }),
9
- routes: [
10
- {
11
- path: `${config.basePath}/[...auth]`,
12
- methods: ["GET", "POST"],
13
- async handler(request) {
14
- const runtime = await getFarmAuthRuntime();
15
- return runtime.handler(request);
16
- },
17
- },
18
- ],
19
- };
20
- }
21
- export async function migrateFarmAuth() {
22
- await runMigration();
23
- }
24
- export async function compileFarmAuthMigration() {
25
- return runCompileMigration();
26
- }
27
- export async function disposeFarmAuth() {
28
- await runDispose();
29
- }
package/dist/runtime.d.ts DELETED
@@ -1,53 +0,0 @@
1
- import type { ResolvedFarmAuthConfig } from "./types.js";
2
- interface FarmAuthRuntimeOptions {
3
- root: string;
4
- mode: "development" | "production";
5
- }
6
- interface BetterAuthRuntime {
7
- handler(request: Request): Promise<Response>;
8
- api: {
9
- getSession(input: {
10
- headers: Headers;
11
- }): Promise<unknown>;
12
- };
13
- }
14
- export declare function configureFarmAuth(config: ResolvedFarmAuthConfig, options: FarmAuthRuntimeOptions): void;
15
- export declare function getFarmAuthRuntime(): Promise<BetterAuthRuntime>;
16
- export declare function getFarmAuthRequest(request?: Request): Request;
17
- /**
18
- * Close the connection opened for the runtime and drop the cached instance.
19
- *
20
- * The runtime is cached on globalThis and its connection stays open for the life
21
- * of the process, which leaves a file lock behind on SQLite and a pool open on
22
- * every other driver. Call this from a teardown hook.
23
- */
24
- export declare function disposeFarmAuth(): Promise<void>;
25
- export declare function migrateFarmAuth(): Promise<void>;
26
- /**
27
- * The statements `migrateFarmAuth` would run, for review before applying them.
28
- * Better Auth owns the schema, so the sql comes from its migrator rather than
29
- * from Farm's own table declarations.
30
- */
31
- export declare function compileFarmAuthMigration(): Promise<string>;
32
- /**
33
- * The origin Better Auth signs cookies and validates requests against.
34
- *
35
- * Better Auth trusts the baseURL's own origin and rejects everything else
36
- * with INVALID_ORIGIN, so this has to resolve to the host users actually
37
- * visit. Vercel exposes two: `VERCEL_URL` is unique per deployment
38
- * (`my-app-a1b2c3.vercel.app`) while `VERCEL_PROJECT_PRODUCTION_URL` is the
39
- * project's canonical domain. Pinning a production deployment to its
40
- * per-deployment hostname rejects every request arriving on the real domain,
41
- * so production prefers the canonical one and previews keep their own URL.
42
- */
43
- export declare function resolveFarmAuthBaseURL(mode: "development" | "production", env?: NodeJS.ProcessEnv): string | undefined;
44
- /**
45
- * Hosts that stay valid alongside the base URL.
46
- *
47
- * A production deployment is still reachable at its own deployment hostname,
48
- * and previews get a fresh one per build, so both are trusted explicitly
49
- * rather than leaving direct deployment-URL access broken.
50
- */
51
- export declare function resolveFarmAuthTrustedOrigins(env?: NodeJS.ProcessEnv): string[];
52
- export {};
53
- //# sourceMappingURL=runtime.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAMzD,UAAU,sBAAsB;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,aAAa,GAAG,YAAY,CAAC;CACpC;AAED,UAAU,iBAAiB;IACzB,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC7C,GAAG,EAAE;QACH,UAAU,CAAC,KAAK,EAAE;YAAE,OAAO,EAAE,OAAO,CAAA;SAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;KAC3D,CAAC;CACH;AAqBD,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,sBAAsB,EAC9B,OAAO,EAAE,sBAAsB,GAC9B,IAAI,CAeN;AAED,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,iBAAiB,CAAC,CA6BrE;AAED,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAU7D;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CASrD;AAED,wBAAsB,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAIrD;AAED;;;;GAIG;AACH,wBAAsB,wBAAwB,IAAI,OAAO,CAAC,MAAM,CAAC,CAEhE;AA4ED;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,aAAa,GAAG,YAAY,EAClC,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,MAAM,GAAG,SAAS,CAWpB;AAED;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,EAAE,CAM5F"}
package/dist/runtime.js DELETED
@@ -1,226 +0,0 @@
1
- import { mkdir } from "node:fs/promises";
2
- import { createRequire } from "node:module";
3
- import path from "node:path";
4
- const FARM_AUTH_STATE_KEY = Symbol.for("@farm.js/auth/runtime");
5
- const CURRENT_REQUEST_RESOLVER_KEY = Symbol.for("farm.currentRequestResolver");
6
- const loadNodeModule = createRequire(import.meta.url);
7
- function getState() {
8
- const runtime = globalThis;
9
- runtime[FARM_AUTH_STATE_KEY] ||= {};
10
- return runtime[FARM_AUTH_STATE_KEY];
11
- }
12
- export function configureFarmAuth(config, options) {
13
- const state = getState();
14
- const changed = JSON.stringify(state.config) !== JSON.stringify(config) ||
15
- state.options?.root !== options.root ||
16
- state.options?.mode !== options.mode;
17
- state.config = config;
18
- state.options = options;
19
- if (changed) {
20
- const previous = state.database;
21
- state.runtime = undefined;
22
- state.database = undefined;
23
- if (previous)
24
- void closeDatabase(previous).catch(() => { });
25
- }
26
- }
27
- export async function getFarmAuthRuntime() {
28
- const state = getState();
29
- if (!state.config?.enabled || !state.options) {
30
- throw new Error("Farm Auth is not enabled. Add `auth: true` to farm.config.ts before using @farm.js/auth.");
31
- }
32
- if (!state.runtime) {
33
- const runtime = createRuntime(state.config, state.options, (database) => {
34
- // A dispose or reconfigure that raced this creation already closed what it
35
- // knew about, so an orphaned connection closes itself instead of leaking.
36
- if (state.runtime === runtime) {
37
- state.database = database;
38
- }
39
- else {
40
- void closeDatabase(database).catch(() => { });
41
- }
42
- });
43
- state.runtime = runtime;
44
- void runtime.catch(() => {
45
- if (state.runtime === runtime) {
46
- state.runtime = undefined;
47
- const database = state.database;
48
- state.database = undefined;
49
- if (database)
50
- void closeDatabase(database).catch(() => { });
51
- }
52
- });
53
- }
54
- return state.runtime;
55
- }
56
- export function getFarmAuthRequest(request) {
57
- if (request)
58
- return request;
59
- const current = globalThis[CURRENT_REQUEST_RESOLVER_KEY]?.();
60
- if (!current) {
61
- throw new Error("No current request is available. Farm Auth server helpers can only be used during a request, or with an explicit `request` option.");
62
- }
63
- return current;
64
- }
65
- /**
66
- * Close the connection opened for the runtime and drop the cached instance.
67
- *
68
- * The runtime is cached on globalThis and its connection stays open for the life
69
- * of the process, which leaves a file lock behind on SQLite and a pool open on
70
- * every other driver. Call this from a teardown hook.
71
- */
72
- export async function disposeFarmAuth() {
73
- const state = getState();
74
- // Let an in-flight creation finish so its connection is registered and closed
75
- // here, instead of resolving before the handle even exists.
76
- if (state.runtime)
77
- await state.runtime.catch(() => { });
78
- const database = state.database;
79
- state.runtime = undefined;
80
- state.database = undefined;
81
- await closeDatabase(database);
82
- }
83
- export async function migrateFarmAuth() {
84
- await withAuthMigrations(async (migrations) => {
85
- await migrations.runMigrations();
86
- });
87
- }
88
- /**
89
- * The statements `migrateFarmAuth` would run, for review before applying them.
90
- * Better Auth owns the schema, so the sql comes from its migrator rather than
91
- * from Farm's own table declarations.
92
- */
93
- export async function compileFarmAuthMigration() {
94
- return withAuthMigrations((migrations) => migrations.compileMigrations());
95
- }
96
- async function withAuthMigrations(use) {
97
- const state = getState();
98
- if (!state.config?.enabled || !state.options) {
99
- throw new Error("Farm Auth is not enabled in farm.config.ts.");
100
- }
101
- const options = await createBetterAuthOptions(state.config, state.options, {
102
- migration: true,
103
- });
104
- const { getMigrations } = await import("better-auth/db/migration");
105
- try {
106
- return await use(await getMigrations(options));
107
- }
108
- finally {
109
- await closeDatabase(options.database);
110
- }
111
- }
112
- async function createRuntime(config, options, onDatabase) {
113
- const authOptions = await createBetterAuthOptions(config, options);
114
- onDatabase(authOptions.database);
115
- if (options.mode === "development" && config.database.migrateInDevelopment) {
116
- const { getMigrations } = await import("better-auth/db/migration");
117
- const migrations = await getMigrations(authOptions);
118
- await migrations.runMigrations();
119
- }
120
- const { betterAuth } = await import("better-auth");
121
- return betterAuth(authOptions);
122
- }
123
- async function createBetterAuthOptions(config, options, runtimeOptions = {}) {
124
- const secret = process.env.FARM_AUTH_SECRET || process.env.AUTH_SECRET || process.env.BETTER_AUTH_SECRET;
125
- if (options.mode === "production" && !secret && !runtimeOptions.migration) {
126
- throw new Error("Farm Auth requires FARM_AUTH_SECRET (or AUTH_SECRET) in production. Generate a random 32-byte secret and add it to your deployment environment.");
127
- }
128
- return {
129
- appName: config.appName || "Farm app",
130
- baseURL: resolveFarmAuthBaseURL(options.mode),
131
- trustedOrigins: resolveFarmAuthTrustedOrigins(),
132
- basePath: config.basePath,
133
- secret: secret || "farm-auth-development-or-migration-secret",
134
- database: await createDatabase(config, options),
135
- emailAndPassword: {
136
- enabled: config.emailAndPassword.enabled,
137
- requireEmailVerification: config.emailAndPassword.requireEmailVerification,
138
- minPasswordLength: config.emailAndPassword.minPasswordLength,
139
- maxPasswordLength: config.emailAndPassword.maxPasswordLength,
140
- },
141
- session: {
142
- expiresIn: config.session.expiresIn,
143
- updateAge: config.session.updateAge,
144
- },
145
- };
146
- }
147
- /**
148
- * The origin Better Auth signs cookies and validates requests against.
149
- *
150
- * Better Auth trusts the baseURL's own origin and rejects everything else
151
- * with INVALID_ORIGIN, so this has to resolve to the host users actually
152
- * visit. Vercel exposes two: `VERCEL_URL` is unique per deployment
153
- * (`my-app-a1b2c3.vercel.app`) while `VERCEL_PROJECT_PRODUCTION_URL` is the
154
- * project's canonical domain. Pinning a production deployment to its
155
- * per-deployment hostname rejects every request arriving on the real domain,
156
- * so production prefers the canonical one and previews keep their own URL.
157
- */
158
- export function resolveFarmAuthBaseURL(mode, env = process.env) {
159
- const configured = env.FARM_AUTH_URL || env.BETTER_AUTH_URL;
160
- if (configured)
161
- return configured;
162
- const vercelHost = env.VERCEL_ENV === "production"
163
- ? env.VERCEL_PROJECT_PRODUCTION_URL || env.VERCEL_URL
164
- : env.VERCEL_URL;
165
- if (vercelHost)
166
- return toAbsoluteOrigin(vercelHost);
167
- return mode === "development" ? "http://localhost:3000" : undefined;
168
- }
169
- /**
170
- * Hosts that stay valid alongside the base URL.
171
- *
172
- * A production deployment is still reachable at its own deployment hostname,
173
- * and previews get a fresh one per build, so both are trusted explicitly
174
- * rather than leaving direct deployment-URL access broken.
175
- */
176
- export function resolveFarmAuthTrustedOrigins(env = process.env) {
177
- const origins = new Set();
178
- for (const host of [env.VERCEL_URL, env.VERCEL_PROJECT_PRODUCTION_URL, env.VERCEL_BRANCH_URL]) {
179
- if (host)
180
- origins.add(toAbsoluteOrigin(host));
181
- }
182
- return [...origins];
183
- }
184
- function toAbsoluteOrigin(host) {
185
- return host.startsWith("http://") || host.startsWith("https://") ? host : `https://${host}`;
186
- }
187
- async function closeDatabase(database) {
188
- if (!database || typeof database !== "object")
189
- return;
190
- const connection = database;
191
- if (typeof connection.end === "function") {
192
- await connection.end();
193
- return;
194
- }
195
- if (typeof connection.close === "function") {
196
- await connection.close();
197
- }
198
- }
199
- async function createDatabase(config, options) {
200
- const databaseUrl = config.database.url || process.env.DATABASE_URL;
201
- if (databaseUrl) {
202
- const { Pool } = await import("pg");
203
- return new Pool({ connectionString: databaseUrl });
204
- }
205
- if (options.mode === "production") {
206
- throw new Error("Farm Auth requires DATABASE_URL in production. Config loading and `farm build` do not connect to the database; the connection is opened only by auth requests or `farm auth migrate`.");
207
- }
208
- const databasePath = path.resolve(options.root, config.database.path);
209
- await mkdir(path.dirname(databasePath), { recursive: true });
210
- try {
211
- const { DatabaseSync } = loadNodeModule("node:sqlite");
212
- return new DatabaseSync(databasePath);
213
- }
214
- catch {
215
- // node:sqlite is available on Node 22+. Keep the native package fallback
216
- // for supported older Node releases.
217
- }
218
- try {
219
- const imported = await import("better-sqlite3");
220
- const Database = imported.default;
221
- return new Database(databasePath);
222
- }
223
- catch (error) {
224
- throw new Error(`Farm Auth could not open its local SQLite database. Install better-sqlite3 or set DATABASE_URL. ${error instanceof Error ? error.message : String(error)}`);
225
- }
226
- }
package/dist/server.d.ts DELETED
@@ -1,19 +0,0 @@
1
- import type { FarmAuthLookupOptions, FarmAuthSession, FarmAuthUser } from "./types.js";
2
- /**
3
- * Farm Auth server helpers. Use `required: true` when anonymous access should
4
- * immediately return a 401 response.
5
- */
6
- declare function session(options: FarmAuthLookupOptions & {
7
- required: true;
8
- }): Promise<FarmAuthSession>;
9
- declare function session(options?: FarmAuthLookupOptions): Promise<FarmAuthSession | null>;
10
- declare function user(options: FarmAuthLookupOptions & {
11
- required: true;
12
- }): Promise<FarmAuthUser>;
13
- declare function user(options?: FarmAuthLookupOptions): Promise<FarmAuthUser | null>;
14
- export declare const auth: {
15
- session: typeof session;
16
- user: typeof user;
17
- };
18
- export type { FarmAuthLookupOptions, FarmAuthSession, FarmAuthSessionData, FarmAuthUser, } from "./types.js";
19
- //# sourceMappingURL=server.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAsBvF;;;GAGG;AACH,iBAAS,OAAO,CAAC,OAAO,EAAE,qBAAqB,GAAG;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;AAChG,iBAAS,OAAO,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;AAKnF,iBAAS,IAAI,CAAC,OAAO,EAAE,qBAAqB,GAAG;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAC1F,iBAAS,IAAI,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;AAK7E,eAAO,MAAM,IAAI;;;CAAoB,CAAC;AAEtC,YAAY,EACV,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EACnB,YAAY,GACb,MAAM,YAAY,CAAC"}
package/dist/server.js DELETED
@@ -1,22 +0,0 @@
1
- import { getFarmAuthRequest, getFarmAuthRuntime } from "./runtime.js";
2
- async function readSession(options = {}) {
3
- const request = getFarmAuthRequest(options.request);
4
- const runtime = await getFarmAuthRuntime();
5
- const session = (await runtime.api.getSession({
6
- headers: request.headers,
7
- }));
8
- if (!session && options.required) {
9
- throw Response.json({
10
- error: "Authentication required",
11
- code: "FARM_AUTH_REQUIRED",
12
- }, { status: 401 });
13
- }
14
- return session;
15
- }
16
- function session(options) {
17
- return readSession(options);
18
- }
19
- async function user(options) {
20
- return (await readSession(options))?.user ?? null;
21
- }
22
- export const auth = { session, user };
package/dist/types.d.ts DELETED
@@ -1,105 +0,0 @@
1
- export interface FarmAuthEmailAndPasswordConfig {
2
- /** Require a verified email before creating a session. @default false */
3
- requireEmailVerification?: boolean;
4
- /** Smallest accepted password length. @default 8 */
5
- minPasswordLength?: number;
6
- /** Largest accepted password length. @default 128 */
7
- maxPasswordLength?: number;
8
- }
9
- export interface FarmAuthSessionConfig {
10
- /** Session lifetime in seconds. @default 604800 */
11
- expiresIn?: number;
12
- /** Session refresh interval in seconds. @default 86400 */
13
- updateAge?: number;
14
- }
15
- export interface FarmAuthDatabaseConfig {
16
- /**
17
- * Postgres connection string. Defaults to DATABASE_URL.
18
- * Local development falls back to SQLite when no URL is present.
19
- */
20
- url?: string;
21
- /** Local SQLite path. @default ".farm/auth.sqlite" */
22
- path?: string;
23
- /** Automatically update the schema in development. @default true */
24
- migrateInDevelopment?: boolean;
25
- }
26
- export interface FarmAuthConfig {
27
- /** Set false to disable auth without removing its configuration. @default true */
28
- enabled?: boolean;
29
- /** Display name used by authentication emails and metadata. */
30
- appName?: string;
31
- /** Route prefix for the auth endpoints. @default "/api/auth" */
32
- basePath?: string;
33
- /**
34
- * Email/password authentication. It is enabled by default; set false to
35
- * disable it when adding another sign-in method.
36
- */
37
- emailAndPassword?: boolean | FarmAuthEmailAndPasswordConfig;
38
- session?: FarmAuthSessionConfig;
39
- database?: FarmAuthDatabaseConfig;
40
- }
41
- export type FarmAuthUserConfig = boolean | FarmAuthConfig;
42
- export interface ResolvedFarmAuthConfig {
43
- enabled: boolean;
44
- appName?: string;
45
- basePath: string;
46
- emailAndPassword: {
47
- enabled: boolean;
48
- requireEmailVerification: boolean;
49
- minPasswordLength: number;
50
- maxPasswordLength: number;
51
- };
52
- session: {
53
- expiresIn: number;
54
- updateAge: number;
55
- };
56
- database: {
57
- url?: string;
58
- path: string;
59
- migrateInDevelopment: boolean;
60
- };
61
- }
62
- export interface FarmAuthUser {
63
- id: string;
64
- name: string;
65
- email: string;
66
- emailVerified: boolean;
67
- image?: string | null;
68
- createdAt: Date;
69
- updatedAt: Date;
70
- }
71
- export interface FarmAuthSessionData {
72
- id: string;
73
- userId: string;
74
- expiresAt: Date;
75
- token: string;
76
- createdAt: Date;
77
- updatedAt: Date;
78
- ipAddress?: string | null;
79
- userAgent?: string | null;
80
- }
81
- export interface FarmAuthSession {
82
- session: FarmAuthSessionData;
83
- user: FarmAuthUser;
84
- }
85
- export interface FarmAuthLookupOptions {
86
- /** Return a 401 Response when no session exists. */
87
- required?: boolean;
88
- /** Override the current Farm request, primarily for route handlers and tests. */
89
- request?: Request;
90
- }
91
- export interface FarmAuthCredentials {
92
- email: string;
93
- password: string;
94
- rememberMe?: boolean;
95
- }
96
- export interface FarmAuthSignUpInput extends FarmAuthCredentials {
97
- name: string;
98
- }
99
- export interface FarmAuthClientOptions {
100
- /** Must match auth.basePath when that option is customized. */
101
- basePath?: string;
102
- /** Optional absolute origin for non-browser clients. */
103
- baseURL?: string;
104
- }
105
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"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"}
package/dist/types.js DELETED
@@ -1 +0,0 @@
1
- export {};