better-convex 0.0.2 → 0.0.4
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/dist/auth/index.d.ts +53 -53
- package/dist/auth-client/index.d.ts +5 -5
- package/dist/auth-client/index.js +140 -49
- package/dist/auth-nextjs/index.js +1 -1
- package/dist/{auth-store-DPj6Z0Xl.js → auth-store-Bu8XzPRV.js} +30 -89
- package/dist/cli.cjs +1 -1
- package/dist/{codegen-P6NmBpvG.cjs → codegen-DN-vbQih.cjs} +1 -1
- package/dist/{error-_XBsa1OD.js → error-DwOaXhPE.js} +4 -2
- package/dist/react/index.d.ts +69 -36
- package/dist/react/index.js +1141 -1042
- package/dist/server/index.d.ts +14 -17
- package/dist/server/index.js +16 -1
- package/dist/watcher.cjs +1 -1
- package/package.json +3 -2
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as better_auth_adapters0 from "better-auth/adapters";
|
|
2
2
|
import { DBAdapterDebugLogOption } from "better-auth/adapters";
|
|
3
3
|
import { BetterAuthDBSchema } from "better-auth/db";
|
|
4
4
|
import * as convex_server24 from "convex/server";
|
|
@@ -44,20 +44,20 @@ declare const createClient: <DataModel extends GenericDataModel, Schema$1 extend
|
|
|
44
44
|
}) => {
|
|
45
45
|
authFunctions: AuthFunctions;
|
|
46
46
|
triggers: Triggers<DataModel, Schema$1> | undefined;
|
|
47
|
-
adapter: (ctx: GenericCtx<DataModel>, createAuthOptions: (ctx: any) => BetterAuthOptions) =>
|
|
48
|
-
httpAdapter: (ctx: GenericCtx<DataModel>) =>
|
|
47
|
+
adapter: (ctx: GenericCtx<DataModel>, createAuthOptions: (ctx: any) => BetterAuthOptions) => better_auth_adapters0.AdapterFactory;
|
|
48
|
+
httpAdapter: (ctx: GenericCtx<DataModel>) => better_auth_adapters0.AdapterFactory;
|
|
49
49
|
triggersApi: () => {
|
|
50
50
|
beforeCreate: convex_server24.RegisteredMutation<"internal", {
|
|
51
|
-
data: any;
|
|
52
51
|
model: string;
|
|
52
|
+
data: any;
|
|
53
53
|
}, Promise<any>>;
|
|
54
54
|
beforeDelete: convex_server24.RegisteredMutation<"internal", {
|
|
55
55
|
model: string;
|
|
56
56
|
doc: any;
|
|
57
57
|
}, Promise<any>>;
|
|
58
58
|
beforeUpdate: convex_server24.RegisteredMutation<"internal", {
|
|
59
|
-
update: any;
|
|
60
59
|
model: string;
|
|
60
|
+
update: any;
|
|
61
61
|
doc: any;
|
|
62
62
|
}, Promise<any>>;
|
|
63
63
|
onCreate: convex_server24.RegisteredMutation<"internal", {
|
|
@@ -148,7 +148,7 @@ declare const httpAdapter: <DataModel extends GenericDataModel, Schema$1 extends
|
|
|
148
148
|
authFunctions: AuthFunctions;
|
|
149
149
|
debugLogs?: DBAdapterDebugLogOption;
|
|
150
150
|
triggers?: Triggers<DataModel, Schema$1>;
|
|
151
|
-
}) =>
|
|
151
|
+
}) => better_auth_adapters0.AdapterFactory;
|
|
152
152
|
declare const dbAdapter: <DataModel extends GenericDataModel, Schema$1 extends SchemaDefinition<any, any>>(ctx: GenericCtx<DataModel>, createAuthOptions: (ctx: any) => BetterAuthOptions, {
|
|
153
153
|
authFunctions,
|
|
154
154
|
debugLogs,
|
|
@@ -159,34 +159,34 @@ declare const dbAdapter: <DataModel extends GenericDataModel, Schema$1 extends S
|
|
|
159
159
|
schema: Schema$1;
|
|
160
160
|
debugLogs?: DBAdapterDebugLogOption;
|
|
161
161
|
triggers?: Triggers<DataModel, Schema$1>;
|
|
162
|
-
}) =>
|
|
162
|
+
}) => better_auth_adapters0.AdapterFactory;
|
|
163
163
|
//#endregion
|
|
164
164
|
//#region src/auth/adapter-utils.d.ts
|
|
165
165
|
declare const adapterWhereValidator: convex_values0.VObject<{
|
|
166
|
-
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
167
166
|
connector?: "AND" | "OR" | undefined;
|
|
168
|
-
|
|
167
|
+
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
169
168
|
field: string;
|
|
169
|
+
value: string | number | boolean | string[] | number[] | null;
|
|
170
170
|
}, {
|
|
171
171
|
connector: convex_values0.VUnion<"AND" | "OR" | undefined, [convex_values0.VLiteral<"AND", "required">, convex_values0.VLiteral<"OR", "required">], "optional", never>;
|
|
172
172
|
field: convex_values0.VString<string, "required">;
|
|
173
|
-
operator: convex_values0.VUnion<"
|
|
173
|
+
operator: convex_values0.VUnion<"lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined, [convex_values0.VLiteral<"lt", "required">, convex_values0.VLiteral<"lte", "required">, convex_values0.VLiteral<"gt", "required">, convex_values0.VLiteral<"gte", "required">, convex_values0.VLiteral<"eq", "required">, convex_values0.VLiteral<"in", "required">, convex_values0.VLiteral<"not_in", "required">, convex_values0.VLiteral<"ne", "required">, convex_values0.VLiteral<"contains", "required">, convex_values0.VLiteral<"starts_with", "required">, convex_values0.VLiteral<"ends_with", "required">], "optional", never>;
|
|
174
174
|
value: convex_values0.VUnion<string | number | boolean | string[] | number[] | null, [convex_values0.VString<string, "required">, convex_values0.VFloat64<number, "required">, convex_values0.VBoolean<boolean, "required">, convex_values0.VArray<string[], convex_values0.VString<string, "required">, "required">, convex_values0.VArray<number[], convex_values0.VFloat64<number, "required">, "required">, convex_values0.VNull<null, "required">], "required", never>;
|
|
175
|
-
}, "required", "
|
|
175
|
+
}, "required", "field" | "connector" | "operator" | "value">;
|
|
176
176
|
declare const adapterArgsValidator: convex_values0.VObject<{
|
|
177
177
|
limit?: number | undefined;
|
|
178
|
-
where?: {
|
|
179
|
-
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
180
|
-
connector?: "AND" | "OR" | undefined;
|
|
181
|
-
value: string | number | boolean | string[] | number[] | null;
|
|
182
|
-
field: string;
|
|
183
|
-
}[] | undefined;
|
|
184
|
-
select?: string[] | undefined;
|
|
185
178
|
offset?: number | undefined;
|
|
179
|
+
select?: string[] | undefined;
|
|
186
180
|
sortBy?: {
|
|
187
|
-
field: string;
|
|
188
181
|
direction: "asc" | "desc";
|
|
182
|
+
field: string;
|
|
189
183
|
} | undefined;
|
|
184
|
+
where?: {
|
|
185
|
+
connector?: "AND" | "OR" | undefined;
|
|
186
|
+
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
187
|
+
field: string;
|
|
188
|
+
value: string | number | boolean | string[] | number[] | null;
|
|
189
|
+
}[] | undefined;
|
|
190
190
|
model: string;
|
|
191
191
|
}, {
|
|
192
192
|
limit: convex_values0.VFloat64<number | undefined, "optional">;
|
|
@@ -194,29 +194,29 @@ declare const adapterArgsValidator: convex_values0.VObject<{
|
|
|
194
194
|
offset: convex_values0.VFloat64<number | undefined, "optional">;
|
|
195
195
|
select: convex_values0.VArray<string[] | undefined, convex_values0.VString<string, "required">, "optional">;
|
|
196
196
|
sortBy: convex_values0.VObject<{
|
|
197
|
-
field: string;
|
|
198
197
|
direction: "asc" | "desc";
|
|
198
|
+
field: string;
|
|
199
199
|
} | undefined, {
|
|
200
200
|
direction: convex_values0.VUnion<"asc" | "desc", [convex_values0.VLiteral<"asc", "required">, convex_values0.VLiteral<"desc", "required">], "required", never>;
|
|
201
201
|
field: convex_values0.VString<string, "required">;
|
|
202
|
-
}, "optional", "
|
|
202
|
+
}, "optional", "direction" | "field">;
|
|
203
203
|
where: convex_values0.VArray<{
|
|
204
|
-
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
205
204
|
connector?: "AND" | "OR" | undefined;
|
|
206
|
-
|
|
205
|
+
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
207
206
|
field: string;
|
|
207
|
+
value: string | number | boolean | string[] | number[] | null;
|
|
208
208
|
}[] | undefined, convex_values0.VObject<{
|
|
209
|
-
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
210
209
|
connector?: "AND" | "OR" | undefined;
|
|
211
|
-
|
|
210
|
+
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
212
211
|
field: string;
|
|
212
|
+
value: string | number | boolean | string[] | number[] | null;
|
|
213
213
|
}, {
|
|
214
214
|
connector: convex_values0.VUnion<"AND" | "OR" | undefined, [convex_values0.VLiteral<"AND", "required">, convex_values0.VLiteral<"OR", "required">], "optional", never>;
|
|
215
215
|
field: convex_values0.VString<string, "required">;
|
|
216
|
-
operator: convex_values0.VUnion<"
|
|
216
|
+
operator: convex_values0.VUnion<"lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined, [convex_values0.VLiteral<"lt", "required">, convex_values0.VLiteral<"lte", "required">, convex_values0.VLiteral<"gt", "required">, convex_values0.VLiteral<"gte", "required">, convex_values0.VLiteral<"eq", "required">, convex_values0.VLiteral<"in", "required">, convex_values0.VLiteral<"not_in", "required">, convex_values0.VLiteral<"ne", "required">, convex_values0.VLiteral<"contains", "required">, convex_values0.VLiteral<"starts_with", "required">, convex_values0.VLiteral<"ends_with", "required">], "optional", never>;
|
|
217
217
|
value: convex_values0.VUnion<string | number | boolean | string[] | number[] | null, [convex_values0.VString<string, "required">, convex_values0.VFloat64<number, "required">, convex_values0.VBoolean<boolean, "required">, convex_values0.VArray<string[], convex_values0.VString<string, "required">, "required">, convex_values0.VArray<number[], convex_values0.VFloat64<number, "required">, "required">, convex_values0.VNull<null, "required">], "required", never>;
|
|
218
|
-
}, "required", "
|
|
219
|
-
}, "required", "limit" | "
|
|
218
|
+
}, "required", "field" | "connector" | "operator" | "value">, "optional">;
|
|
219
|
+
}, "required", "limit" | "model" | "offset" | "select" | "sortBy" | "where" | "sortBy.direction" | "sortBy.field">;
|
|
220
220
|
declare const hasUniqueFields: (betterAuthSchema: BetterAuthDBSchema, model: string, input: Record<string, any>) => boolean;
|
|
221
221
|
declare const checkUniqueFields: <Schema$1 extends SchemaDefinition<any, any>>(ctx: GenericQueryCtx<GenericDataModel>, schema: Schema$1, betterAuthSchema: BetterAuthDBSchema, table: string, input: Record<string, any>, doc?: Record<string, any>) => Promise<void>;
|
|
222
222
|
declare const selectFields: <T extends TableNamesInDataModel<GenericDataModel>, D extends DocumentByName<GenericDataModel, T>>(doc: D | null, select?: string[]) => Promise<D | null>;
|
|
@@ -318,15 +318,15 @@ declare const createApi: <Schema$1 extends SchemaDefinition<any, any>>(schema: S
|
|
|
318
318
|
beforeCreateHandle?: string | undefined;
|
|
319
319
|
onCreateHandle?: string | undefined;
|
|
320
320
|
input: {
|
|
321
|
-
data: any;
|
|
322
321
|
model: string;
|
|
322
|
+
data: any;
|
|
323
323
|
} | {
|
|
324
|
+
model: string;
|
|
324
325
|
data: {
|
|
325
326
|
[x: string]: unknown;
|
|
326
327
|
[x: number]: unknown;
|
|
327
328
|
[x: symbol]: unknown;
|
|
328
329
|
};
|
|
329
|
-
model: string;
|
|
330
330
|
};
|
|
331
331
|
}, Promise<any>>;
|
|
332
332
|
deleteMany: convex_server24.RegisteredMutation<"internal", {
|
|
@@ -345,10 +345,10 @@ declare const createApi: <Schema$1 extends SchemaDefinition<any, any>>(schema: S
|
|
|
345
345
|
model: string;
|
|
346
346
|
} | {
|
|
347
347
|
where?: {
|
|
348
|
-
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
349
348
|
connector?: "AND" | "OR" | undefined;
|
|
350
|
-
|
|
349
|
+
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
351
350
|
field: string;
|
|
351
|
+
value: string | number | boolean | string[] | number[] | null;
|
|
352
352
|
}[] | undefined;
|
|
353
353
|
model: string;
|
|
354
354
|
};
|
|
@@ -368,10 +368,10 @@ declare const createApi: <Schema$1 extends SchemaDefinition<any, any>>(schema: S
|
|
|
368
368
|
model: string;
|
|
369
369
|
} | {
|
|
370
370
|
where?: {
|
|
371
|
-
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
372
371
|
connector?: "AND" | "OR" | undefined;
|
|
373
|
-
|
|
372
|
+
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
374
373
|
field: string;
|
|
374
|
+
value: string | number | boolean | string[] | number[] | null;
|
|
375
375
|
}[] | undefined;
|
|
376
376
|
model: string;
|
|
377
377
|
};
|
|
@@ -379,17 +379,18 @@ declare const createApi: <Schema$1 extends SchemaDefinition<any, any>>(schema: S
|
|
|
379
379
|
findMany: convex_server24.RegisteredQuery<"internal", {
|
|
380
380
|
limit?: number | undefined;
|
|
381
381
|
join?: any;
|
|
382
|
-
where?: {
|
|
383
|
-
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
384
|
-
connector?: "AND" | "OR" | undefined;
|
|
385
|
-
value: string | number | boolean | string[] | number[] | null;
|
|
386
|
-
field: string;
|
|
387
|
-
}[] | undefined;
|
|
388
382
|
offset?: number | undefined;
|
|
389
383
|
sortBy?: {
|
|
390
|
-
field: string;
|
|
391
384
|
direction: "asc" | "desc";
|
|
385
|
+
field: string;
|
|
392
386
|
} | undefined;
|
|
387
|
+
where?: {
|
|
388
|
+
connector?: "AND" | "OR" | undefined;
|
|
389
|
+
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
390
|
+
field: string;
|
|
391
|
+
value: string | number | boolean | string[] | number[] | null;
|
|
392
|
+
}[] | undefined;
|
|
393
|
+
model: string;
|
|
393
394
|
paginationOpts: {
|
|
394
395
|
id?: number;
|
|
395
396
|
endCursor?: string | null;
|
|
@@ -398,17 +399,16 @@ declare const createApi: <Schema$1 extends SchemaDefinition<any, any>>(schema: S
|
|
|
398
399
|
numItems: number;
|
|
399
400
|
cursor: string | null;
|
|
400
401
|
};
|
|
401
|
-
model: string;
|
|
402
402
|
}, Promise<convex_server24.PaginationResult<convex_server24.GenericDocument>>>;
|
|
403
403
|
findOne: convex_server24.RegisteredQuery<"internal", {
|
|
404
404
|
join?: any;
|
|
405
|
+
select?: string[] | undefined;
|
|
405
406
|
where?: {
|
|
406
|
-
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
407
407
|
connector?: "AND" | "OR" | undefined;
|
|
408
|
-
|
|
408
|
+
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
409
409
|
field: string;
|
|
410
|
+
value: string | number | boolean | string[] | number[] | null;
|
|
410
411
|
}[] | undefined;
|
|
411
|
-
select?: string[] | undefined;
|
|
412
412
|
model: string;
|
|
413
413
|
}, Promise<convex_server24.GenericDocument | null>>;
|
|
414
414
|
updateMany: convex_server24.RegisteredMutation<"internal", {
|
|
@@ -424,21 +424,21 @@ declare const createApi: <Schema$1 extends SchemaDefinition<any, any>>(schema: S
|
|
|
424
424
|
};
|
|
425
425
|
input: {
|
|
426
426
|
where?: any[] | undefined;
|
|
427
|
-
update: any;
|
|
428
427
|
model: string;
|
|
428
|
+
update: any;
|
|
429
429
|
} | {
|
|
430
430
|
where?: {
|
|
431
|
-
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
432
431
|
connector?: "AND" | "OR" | undefined;
|
|
433
|
-
|
|
432
|
+
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
434
433
|
field: string;
|
|
434
|
+
value: string | number | boolean | string[] | number[] | null;
|
|
435
435
|
}[] | undefined;
|
|
436
|
+
model: string;
|
|
436
437
|
update: {
|
|
437
438
|
[x: string]: unknown;
|
|
438
439
|
[x: number]: unknown;
|
|
439
440
|
[x: symbol]: unknown;
|
|
440
441
|
};
|
|
441
|
-
model: string;
|
|
442
442
|
};
|
|
443
443
|
}, Promise<{
|
|
444
444
|
count: number;
|
|
@@ -453,21 +453,21 @@ declare const createApi: <Schema$1 extends SchemaDefinition<any, any>>(schema: S
|
|
|
453
453
|
onUpdateHandle?: string | undefined;
|
|
454
454
|
input: {
|
|
455
455
|
where?: any[] | undefined;
|
|
456
|
-
update: any;
|
|
457
456
|
model: string;
|
|
457
|
+
update: any;
|
|
458
458
|
} | {
|
|
459
459
|
where?: {
|
|
460
|
-
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
461
460
|
connector?: "AND" | "OR" | undefined;
|
|
462
|
-
|
|
461
|
+
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
463
462
|
field: string;
|
|
463
|
+
value: string | number | boolean | string[] | number[] | null;
|
|
464
464
|
}[] | undefined;
|
|
465
|
+
model: string;
|
|
465
466
|
update: {
|
|
466
467
|
[x: string]: unknown;
|
|
467
468
|
[x: number]: unknown;
|
|
468
469
|
[x: symbol]: unknown;
|
|
469
470
|
};
|
|
470
|
-
model: string;
|
|
471
471
|
};
|
|
472
472
|
}, Promise<any>>;
|
|
473
473
|
getLatestJwks: convex_server24.RegisteredAction<"internal", {}, Promise<any>>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { AuthClient } from "@convex-dev/better-auth/react";
|
|
3
2
|
import { ConvexReactClient } from "convex/react";
|
|
4
3
|
import { ReactNode } from "react";
|
|
5
4
|
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
5
|
+
import { AuthClient, AuthClient as AuthClient$1 } from "@convex-dev/better-auth/react";
|
|
6
6
|
|
|
7
7
|
//#region src/auth-client/convex-auth-provider.d.ts
|
|
8
8
|
type ConvexAuthProviderProps = {
|
|
@@ -10,7 +10,7 @@ type ConvexAuthProviderProps = {
|
|
|
10
10
|
/** Convex client instance */
|
|
11
11
|
client: ConvexReactClient;
|
|
12
12
|
/** Better Auth client instance */
|
|
13
|
-
authClient: AuthClient;
|
|
13
|
+
authClient: AuthClient$1;
|
|
14
14
|
/** Initial session token (from SSR) */
|
|
15
15
|
initialToken?: string;
|
|
16
16
|
/** Callback when mutation called while unauthorized */
|
|
@@ -21,8 +21,8 @@ type ConvexAuthProviderProps = {
|
|
|
21
21
|
}) => void;
|
|
22
22
|
};
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
24
|
+
* Unified auth provider for Convex + Better Auth.
|
|
25
|
+
* Handles token sync, HMR persistence, and auth callbacks.
|
|
26
26
|
*/
|
|
27
27
|
declare function ConvexAuthProvider({
|
|
28
28
|
children,
|
|
@@ -33,4 +33,4 @@ declare function ConvexAuthProvider({
|
|
|
33
33
|
onQueryUnauthorized
|
|
34
34
|
}: ConvexAuthProviderProps): react_jsx_runtime0.JSX.Element;
|
|
35
35
|
//#endregion
|
|
36
|
-
export { ConvexAuthProvider, ConvexAuthProviderProps };
|
|
36
|
+
export { type AuthClient, ConvexAuthProvider, ConvexAuthProviderProps };
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
2
|
+
import { c as persistToken, f as useAuthStore, g as CRPCClientError, p as useAuthValue, s as getPersistedToken, t as AuthProvider } from "../auth-store-Bu8XzPRV.js";
|
|
3
3
|
import { c } from "react/compiler-runtime";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { ConvexProviderWithAuth } from "convex/react";
|
|
5
|
+
import { useCallback, useEffect, useMemo } from "react";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
7
|
|
|
7
8
|
//#region src/auth-client/convex-auth-provider.tsx
|
|
9
|
+
/**
|
|
10
|
+
* Unified Convex + Better Auth provider
|
|
11
|
+
*/
|
|
8
12
|
const defaultMutationHandler = () => {
|
|
9
13
|
throw new CRPCClientError({
|
|
10
14
|
code: "UNAUTHORIZED",
|
|
@@ -12,11 +16,11 @@ const defaultMutationHandler = () => {
|
|
|
12
16
|
});
|
|
13
17
|
};
|
|
14
18
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
19
|
+
* Unified auth provider for Convex + Better Auth.
|
|
20
|
+
* Handles token sync, HMR persistence, and auth callbacks.
|
|
17
21
|
*/
|
|
18
22
|
function ConvexAuthProvider(t0) {
|
|
19
|
-
const $ = c(
|
|
23
|
+
const $ = c(16);
|
|
20
24
|
const { children, client, authClient, initialToken, onMutationUnauthorized, onQueryUnauthorized } = t0;
|
|
21
25
|
let t1;
|
|
22
26
|
if ($[0] !== initialToken) {
|
|
@@ -26,55 +30,142 @@ function ConvexAuthProvider(t0) {
|
|
|
26
30
|
} else t1 = $[1];
|
|
27
31
|
const effectiveToken = t1;
|
|
28
32
|
if (effectiveToken) persistToken(effectiveToken);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
let t3;
|
|
37
|
-
if ($[2] !== t2) {
|
|
38
|
-
t3 = {
|
|
33
|
+
const useAuth = useCreateConvexAuth(authClient);
|
|
34
|
+
useOTTHandler(authClient);
|
|
35
|
+
const t2 = client;
|
|
36
|
+
const t3 = effectiveToken ?? null;
|
|
37
|
+
let t4;
|
|
38
|
+
if ($[2] !== t3) {
|
|
39
|
+
t4 = {
|
|
39
40
|
isLoading: true,
|
|
40
|
-
token:
|
|
41
|
+
token: t3
|
|
41
42
|
};
|
|
42
|
-
$[2] =
|
|
43
|
-
$[3] =
|
|
44
|
-
} else
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
let t6;
|
|
48
|
-
if ($[4] !== children || $[5] !== t3 || $[6] !== t4 || $[7] !== t5) {
|
|
49
|
-
t6 = /* @__PURE__ */ jsx(AuthProvider, {
|
|
50
|
-
initialValues: t3,
|
|
51
|
-
onMutationUnauthorized: t4,
|
|
52
|
-
onQueryUnauthorized: t5,
|
|
53
|
-
children
|
|
54
|
-
});
|
|
55
|
-
$[4] = children;
|
|
56
|
-
$[5] = t3;
|
|
57
|
-
$[6] = t4;
|
|
58
|
-
$[7] = t5;
|
|
59
|
-
$[8] = t6;
|
|
60
|
-
} else t6 = $[8];
|
|
43
|
+
$[2] = t3;
|
|
44
|
+
$[3] = t4;
|
|
45
|
+
} else t4 = $[3];
|
|
46
|
+
const t5 = onMutationUnauthorized ?? defaultMutationHandler;
|
|
47
|
+
const t6 = onQueryUnauthorized ?? _temp;
|
|
61
48
|
let t7;
|
|
62
|
-
if ($[
|
|
63
|
-
t7 = /* @__PURE__ */ jsx(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
49
|
+
if ($[4] !== authClient) {
|
|
50
|
+
t7 = /* @__PURE__ */ jsx(AuthSyncEffect, { authClient });
|
|
51
|
+
$[4] = authClient;
|
|
52
|
+
$[5] = t7;
|
|
53
|
+
} else t7 = $[5];
|
|
54
|
+
let t8;
|
|
55
|
+
if ($[6] !== children || $[7] !== t4 || $[8] !== t5 || $[9] !== t6 || $[10] !== t7) {
|
|
56
|
+
t8 = /* @__PURE__ */ jsxs(AuthProvider, {
|
|
57
|
+
initialValues: t4,
|
|
58
|
+
onMutationUnauthorized: t5,
|
|
59
|
+
onQueryUnauthorized: t6,
|
|
60
|
+
children: [t7, children]
|
|
68
61
|
});
|
|
69
|
-
$[
|
|
70
|
-
$[
|
|
71
|
-
$[
|
|
72
|
-
$[
|
|
73
|
-
$[
|
|
74
|
-
|
|
75
|
-
|
|
62
|
+
$[6] = children;
|
|
63
|
+
$[7] = t4;
|
|
64
|
+
$[8] = t5;
|
|
65
|
+
$[9] = t6;
|
|
66
|
+
$[10] = t7;
|
|
67
|
+
$[11] = t8;
|
|
68
|
+
} else t8 = $[11];
|
|
69
|
+
let t9;
|
|
70
|
+
if ($[12] !== t2 || $[13] !== t8 || $[14] !== useAuth) {
|
|
71
|
+
t9 = /* @__PURE__ */ jsx(ConvexProviderWithAuth, {
|
|
72
|
+
client: t2,
|
|
73
|
+
useAuth,
|
|
74
|
+
children: t8
|
|
75
|
+
});
|
|
76
|
+
$[12] = t2;
|
|
77
|
+
$[13] = t8;
|
|
78
|
+
$[14] = useAuth;
|
|
79
|
+
$[15] = t9;
|
|
80
|
+
} else t9 = $[15];
|
|
81
|
+
return t9;
|
|
76
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Syncs Better Auth session to auth-store.
|
|
85
|
+
* Automatically handles login/logout token updates.
|
|
86
|
+
*/
|
|
77
87
|
function _temp() {}
|
|
88
|
+
function AuthSyncEffect({ authClient }) {
|
|
89
|
+
const session = authClient.useSession();
|
|
90
|
+
const authStore = useAuthStore();
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
if (!session.isPending) {
|
|
93
|
+
const token = session.data?.session.token ?? null;
|
|
94
|
+
if (token !== authStore.get("token")) {
|
|
95
|
+
authStore.set("token", token);
|
|
96
|
+
persistToken(token);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}, [
|
|
100
|
+
session.data,
|
|
101
|
+
session.isPending,
|
|
102
|
+
authStore
|
|
103
|
+
]);
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Creates useAuth hook for ConvexProviderWithAuth.
|
|
108
|
+
* Uses auth-store token as single source of truth.
|
|
109
|
+
*/
|
|
110
|
+
function useCreateConvexAuth(authClient) {
|
|
111
|
+
return useMemo(() => function useConvexAuth$1() {
|
|
112
|
+
const { data: session, isPending: isSessionPending } = authClient.useSession();
|
|
113
|
+
const token = useAuthValue("token");
|
|
114
|
+
const sessionId = session?.session?.id;
|
|
115
|
+
const fetchAccessToken = useCallback(async ({ forceRefreshToken = false } = {}) => {
|
|
116
|
+
if (token && !forceRefreshToken) return token;
|
|
117
|
+
try {
|
|
118
|
+
const { data } = await authClient.convex.token();
|
|
119
|
+
return data?.token || null;
|
|
120
|
+
} catch {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
}, [sessionId, token]);
|
|
124
|
+
return useMemo(() => ({
|
|
125
|
+
isLoading: isSessionPending,
|
|
126
|
+
isAuthenticated: session !== null,
|
|
127
|
+
fetchAccessToken
|
|
128
|
+
}), [
|
|
129
|
+
isSessionPending,
|
|
130
|
+
sessionId,
|
|
131
|
+
fetchAccessToken
|
|
132
|
+
]);
|
|
133
|
+
}, [authClient]);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Handles cross-domain one-time token (OTT) verification.
|
|
137
|
+
*/
|
|
138
|
+
function useOTTHandler(authClient) {
|
|
139
|
+
const $ = c(3);
|
|
140
|
+
let t0;
|
|
141
|
+
let t1;
|
|
142
|
+
if ($[0] !== authClient) {
|
|
143
|
+
t0 = () => {
|
|
144
|
+
(async () => {
|
|
145
|
+
const url = new URL(window.location?.href);
|
|
146
|
+
const token = url.searchParams.get("ott");
|
|
147
|
+
if (token) {
|
|
148
|
+
const authClientWithCrossDomain = authClient;
|
|
149
|
+
url.searchParams.delete("ott");
|
|
150
|
+
const session = (await authClientWithCrossDomain.crossDomain.oneTimeToken.verify({ token })).data?.session;
|
|
151
|
+
if (session) {
|
|
152
|
+
await authClient.getSession({ fetchOptions: { headers: { Authorization: `Bearer ${session.token}` } } });
|
|
153
|
+
authClientWithCrossDomain.updateSession();
|
|
154
|
+
}
|
|
155
|
+
window.history.replaceState({}, "", url);
|
|
156
|
+
}
|
|
157
|
+
})();
|
|
158
|
+
};
|
|
159
|
+
t1 = [authClient];
|
|
160
|
+
$[0] = authClient;
|
|
161
|
+
$[1] = t0;
|
|
162
|
+
$[2] = t1;
|
|
163
|
+
} else {
|
|
164
|
+
t0 = $[1];
|
|
165
|
+
t1 = $[2];
|
|
166
|
+
}
|
|
167
|
+
useEffect(t0, t1);
|
|
168
|
+
}
|
|
78
169
|
|
|
79
170
|
//#endregion
|
|
80
171
|
export { ConvexAuthProvider };
|