better-convex 0.7.0 → 0.7.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/dist/aggregate/index.d.ts +2 -0
- package/dist/auth/client/index.js +31 -14
- package/dist/auth/index.d.ts +70 -69
- package/dist/auth/index.js +30 -3
- package/dist/auth/nextjs/index.js +14 -9
- package/dist/{caller-factory-Dmgv8MLS.js → caller-factory-D3OuR1eI.js} +5 -2
- package/dist/react/index.js +7 -1
- package/dist/server/index.js +1 -1
- package/package.json +2 -2
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Ft as ConvexTableWithColumns, J as ConvexTextBuilderInitial, Z as ConvexNumberBuilderInitial, et as ConvexIdBuilderInitial, st as ConvexCustomBuilderInitial } from "../where-clause-compiler-CRP-i1Qa.js";
|
|
2
|
+
import "../query-context-DGExXZIV.js";
|
|
3
|
+
import "../orm/index.js";
|
|
2
4
|
import * as convex_values0 from "convex/values";
|
|
3
5
|
import { GenericId, Infer, Value } from "convex/values";
|
|
4
6
|
import { DocumentByName, GenericDataModel, GenericDatabaseReader, GenericDatabaseWriter, TableNamesInDataModel } from "convex/server";
|
|
@@ -16,6 +16,10 @@ const defaultMutationHandler = () => {
|
|
|
16
16
|
functionName: "mutation"
|
|
17
17
|
});
|
|
18
18
|
};
|
|
19
|
+
const hasActiveSessionData = (session) => {
|
|
20
|
+
if (!session || typeof session !== "object") return false;
|
|
21
|
+
return Boolean(session.session);
|
|
22
|
+
};
|
|
19
23
|
/**
|
|
20
24
|
* Unified auth provider for Convex + Better Auth.
|
|
21
25
|
* Handles token sync, HMR persistence, and auth callbacks.
|
|
@@ -88,10 +92,11 @@ function ConvexAuthProviderInner({ children, client, authClient }) {
|
|
|
88
92
|
const { data: session, isPending } = authClient.useSession();
|
|
89
93
|
const sessionRef = useRef(session);
|
|
90
94
|
const isPendingRef = useRef(isPending);
|
|
95
|
+
const pendingTokenRef = useRef(null);
|
|
91
96
|
sessionRef.current = session;
|
|
92
97
|
isPendingRef.current = isPending;
|
|
93
98
|
useEffect(() => {
|
|
94
|
-
if (!session && !isPending) {
|
|
99
|
+
if (!hasActiveSessionData(session) && !isPending) {
|
|
95
100
|
authStore.set("token", null);
|
|
96
101
|
authStore.set("expiresAt", null);
|
|
97
102
|
authStore.set("isAuthenticated", false);
|
|
@@ -104,7 +109,7 @@ function ConvexAuthProviderInner({ children, client, authClient }) {
|
|
|
104
109
|
const fetchAccessToken = useCallback(async ({ forceRefreshToken = false } = {}) => {
|
|
105
110
|
const currentSession = sessionRef.current;
|
|
106
111
|
const currentIsPending = isPendingRef.current;
|
|
107
|
-
if (!currentSession) {
|
|
112
|
+
if (!hasActiveSessionData(currentSession)) {
|
|
108
113
|
if (!currentIsPending) {
|
|
109
114
|
authStore.set("token", null);
|
|
110
115
|
authStore.set("expiresAt", null);
|
|
@@ -115,27 +120,38 @@ function ConvexAuthProviderInner({ children, client, authClient }) {
|
|
|
115
120
|
const expiresAt = authStore.get("expiresAt");
|
|
116
121
|
const timeRemaining = expiresAt ? expiresAt - Date.now() : 0;
|
|
117
122
|
if (!forceRefreshToken && cachedToken && expiresAt && timeRemaining >= 6e4) return cachedToken;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const jwt = data?.token || null;
|
|
123
|
+
if (!forceRefreshToken && pendingTokenRef.current) return pendingTokenRef.current;
|
|
124
|
+
pendingTokenRef.current = authClient.convex.token({ fetchOptions: { throw: false } }).then((result) => {
|
|
125
|
+
const jwt = result.data?.token || null;
|
|
121
126
|
if (jwt) {
|
|
122
127
|
const exp = decodeJwtExp(jwt);
|
|
123
128
|
authStore.set("token", jwt);
|
|
124
129
|
authStore.set("expiresAt", exp);
|
|
130
|
+
return jwt;
|
|
125
131
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
console.error("[fetchAccessToken] error", e);
|
|
132
|
+
authStore.set("token", null);
|
|
133
|
+
authStore.set("expiresAt", null);
|
|
129
134
|
return null;
|
|
130
|
-
}
|
|
135
|
+
}).catch((error) => {
|
|
136
|
+
authStore.set("token", null);
|
|
137
|
+
authStore.set("expiresAt", null);
|
|
138
|
+
console.error("[fetchAccessToken] error", error);
|
|
139
|
+
return null;
|
|
140
|
+
}).finally(() => {
|
|
141
|
+
pendingTokenRef.current = null;
|
|
142
|
+
});
|
|
143
|
+
return pendingTokenRef.current;
|
|
131
144
|
}, [authStore, authClient]);
|
|
132
145
|
const useAuth = useCallback(function useConvexAuthHook() {
|
|
146
|
+
const token = authStore.get("token");
|
|
147
|
+
const hasSession_0 = hasActiveSessionData(sessionRef.current);
|
|
148
|
+
const sessionMissing = !hasSession_0 && !isPendingRef.current;
|
|
133
149
|
return {
|
|
134
|
-
isLoading: isPendingRef.current,
|
|
135
|
-
isAuthenticated:
|
|
150
|
+
isLoading: isPendingRef.current && !token,
|
|
151
|
+
isAuthenticated: sessionMissing ? false : hasSession_0 || token !== null,
|
|
136
152
|
fetchAccessToken
|
|
137
153
|
};
|
|
138
|
-
}, [fetchAccessToken]);
|
|
154
|
+
}, [fetchAccessToken, authStore]);
|
|
139
155
|
return /* @__PURE__ */ jsx(FetchAccessTokenContext.Provider, {
|
|
140
156
|
value: fetchAccessToken,
|
|
141
157
|
children: /* @__PURE__ */ jsx(ConvexProviderWithAuth, {
|
|
@@ -200,17 +216,18 @@ function useOTTHandler(authClient) {
|
|
|
200
216
|
if ($[0] !== authClient) {
|
|
201
217
|
t0 = () => {
|
|
202
218
|
(async () => {
|
|
203
|
-
|
|
219
|
+
if (typeof window === "undefined" || !window.location?.href) return;
|
|
220
|
+
const url = new URL(window.location.href);
|
|
204
221
|
const token = url.searchParams.get("ott");
|
|
205
222
|
if (token) {
|
|
206
223
|
const authClientWithCrossDomain = authClient;
|
|
207
224
|
url.searchParams.delete("ott");
|
|
225
|
+
window.history.replaceState({}, "", url);
|
|
208
226
|
const session = (await authClientWithCrossDomain.crossDomain.oneTimeToken.verify({ token })).data?.session;
|
|
209
227
|
if (session) {
|
|
210
228
|
await authClient.getSession({ fetchOptions: { headers: { Authorization: `Bearer ${session.token}` } } });
|
|
211
229
|
authClientWithCrossDomain.updateSession();
|
|
212
230
|
}
|
|
213
|
-
window.history.replaceState({}, "", url);
|
|
214
231
|
}
|
|
215
232
|
})();
|
|
216
233
|
};
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -11,8 +11,9 @@ import { convex } from "@convex-dev/better-auth/plugins";
|
|
|
11
11
|
import * as better_auth_adapters0 from "better-auth/adapters";
|
|
12
12
|
import { DBAdapterDebugLogOption } from "better-auth/adapters";
|
|
13
13
|
import { BetterAuthDBSchema } from "better-auth/db";
|
|
14
|
+
import { BetterAuthOptions, betterAuth } from "better-auth/minimal";
|
|
14
15
|
import * as better_auth0 from "better-auth";
|
|
15
|
-
import {
|
|
16
|
+
import { Where } from "better-auth/types";
|
|
16
17
|
import { SetOptional } from "type-fest";
|
|
17
18
|
import * as bun_sqlite0 from "bun:sqlite";
|
|
18
19
|
import * as node_sqlite0 from "node:sqlite";
|
|
@@ -181,15 +182,15 @@ type AdapterPaginationOptions = PaginationOptions & {
|
|
|
181
182
|
};
|
|
182
183
|
declare const adapterWhereValidator: convex_values0.VObject<{
|
|
183
184
|
connector?: "AND" | "OR" | undefined;
|
|
184
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
185
|
-
field: string;
|
|
185
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
186
186
|
value: string | number | boolean | string[] | number[] | null;
|
|
187
|
+
field: string;
|
|
187
188
|
}, {
|
|
188
189
|
connector: convex_values0.VUnion<"AND" | "OR" | undefined, [convex_values0.VLiteral<"AND", "required">, convex_values0.VLiteral<"OR", "required">], "optional", never>;
|
|
189
190
|
field: convex_values0.VString<string, "required">;
|
|
190
|
-
operator: convex_values0.VUnion<"lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
191
|
+
operator: convex_values0.VUnion<"in" | "lt" | "lte" | "gt" | "gte" | "eq" | "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>;
|
|
191
192
|
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>;
|
|
192
|
-
}, "required", "
|
|
193
|
+
}, "required", "value" | "connector" | "field" | "operator">;
|
|
193
194
|
declare const adapterArgsValidator: convex_values0.VObject<{
|
|
194
195
|
limit?: number | undefined;
|
|
195
196
|
select?: string[] | undefined;
|
|
@@ -200,9 +201,9 @@ declare const adapterArgsValidator: convex_values0.VObject<{
|
|
|
200
201
|
} | undefined;
|
|
201
202
|
where?: {
|
|
202
203
|
connector?: "AND" | "OR" | undefined;
|
|
203
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
204
|
-
field: string;
|
|
204
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
205
205
|
value: string | number | boolean | string[] | number[] | null;
|
|
206
|
+
field: string;
|
|
206
207
|
}[] | undefined;
|
|
207
208
|
model: string;
|
|
208
209
|
}, {
|
|
@@ -219,20 +220,20 @@ declare const adapterArgsValidator: convex_values0.VObject<{
|
|
|
219
220
|
}, "optional", "field" | "direction">;
|
|
220
221
|
where: convex_values0.VArray<{
|
|
221
222
|
connector?: "AND" | "OR" | undefined;
|
|
222
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
223
|
-
field: string;
|
|
223
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
224
224
|
value: string | number | boolean | string[] | number[] | null;
|
|
225
|
+
field: string;
|
|
225
226
|
}[] | undefined, convex_values0.VObject<{
|
|
226
227
|
connector?: "AND" | "OR" | undefined;
|
|
227
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
228
|
-
field: string;
|
|
228
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
229
229
|
value: string | number | boolean | string[] | number[] | null;
|
|
230
|
+
field: string;
|
|
230
231
|
}, {
|
|
231
232
|
connector: convex_values0.VUnion<"AND" | "OR" | undefined, [convex_values0.VLiteral<"AND", "required">, convex_values0.VLiteral<"OR", "required">], "optional", never>;
|
|
232
233
|
field: convex_values0.VString<string, "required">;
|
|
233
|
-
operator: convex_values0.VUnion<"lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
234
|
+
operator: convex_values0.VUnion<"in" | "lt" | "lte" | "gt" | "gte" | "eq" | "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>;
|
|
234
235
|
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>;
|
|
235
|
-
}, "required", "
|
|
236
|
+
}, "required", "value" | "connector" | "field" | "operator">, "optional">;
|
|
236
237
|
}, "required", "limit" | "model" | "select" | "offset" | "sortBy" | "where" | "sortBy.field" | "sortBy.direction">;
|
|
237
238
|
declare const hasUniqueFields: (betterAuthSchema: BetterAuthDBSchema, model: string, input: Record<string, any>) => boolean;
|
|
238
239
|
declare const checkUniqueFields: <Schema extends SchemaDefinition<any, any>>(ctx: GenericQueryCtx<GenericDataModel>, schema: Schema, betterAuthSchema: BetterAuthDBSchema, table: string, input: Record<string, any>, doc?: Record<string, any>) => Promise<void>;
|
|
@@ -358,26 +359,26 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>, DataModel e
|
|
|
358
359
|
};
|
|
359
360
|
}, Promise<any>>;
|
|
360
361
|
deleteMany: convex_server0.RegisteredMutation<"internal", {
|
|
361
|
-
paginationOpts: {
|
|
362
|
-
id?: number;
|
|
363
|
-
endCursor?: string | null;
|
|
364
|
-
maximumRowsRead?: number;
|
|
365
|
-
maximumBytesRead?: number;
|
|
366
|
-
numItems: number;
|
|
367
|
-
cursor: string | null;
|
|
368
|
-
};
|
|
369
362
|
input: {
|
|
370
363
|
where?: {
|
|
371
364
|
connector?: "AND" | "OR" | undefined;
|
|
372
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
373
|
-
field: string;
|
|
365
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
374
366
|
value: string | number | boolean | string[] | number[] | null;
|
|
367
|
+
field: string;
|
|
375
368
|
}[] | undefined;
|
|
376
369
|
model: string;
|
|
377
370
|
} | {
|
|
378
371
|
where?: any[] | undefined;
|
|
379
372
|
model: string;
|
|
380
373
|
};
|
|
374
|
+
paginationOpts: {
|
|
375
|
+
id?: number;
|
|
376
|
+
endCursor?: string | null;
|
|
377
|
+
maximumRowsRead?: number;
|
|
378
|
+
maximumBytesRead?: number;
|
|
379
|
+
numItems: number;
|
|
380
|
+
cursor: string | null;
|
|
381
|
+
};
|
|
381
382
|
}, Promise<{
|
|
382
383
|
count: number;
|
|
383
384
|
ids: any[];
|
|
@@ -390,9 +391,9 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>, DataModel e
|
|
|
390
391
|
input: {
|
|
391
392
|
where?: {
|
|
392
393
|
connector?: "AND" | "OR" | undefined;
|
|
393
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
394
|
-
field: string;
|
|
394
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
395
395
|
value: string | number | boolean | string[] | number[] | null;
|
|
396
|
+
field: string;
|
|
396
397
|
}[] | undefined;
|
|
397
398
|
model: string;
|
|
398
399
|
} | {
|
|
@@ -410,9 +411,9 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>, DataModel e
|
|
|
410
411
|
} | undefined;
|
|
411
412
|
where?: {
|
|
412
413
|
connector?: "AND" | "OR" | undefined;
|
|
413
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
414
|
-
field: string;
|
|
414
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
415
415
|
value: string | number | boolean | string[] | number[] | null;
|
|
416
|
+
field: string;
|
|
416
417
|
}[] | undefined;
|
|
417
418
|
paginationOpts: {
|
|
418
419
|
id?: number;
|
|
@@ -429,27 +430,19 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>, DataModel e
|
|
|
429
430
|
select?: string[] | undefined;
|
|
430
431
|
where?: {
|
|
431
432
|
connector?: "AND" | "OR" | undefined;
|
|
432
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
433
|
-
field: string;
|
|
433
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
434
434
|
value: string | number | boolean | string[] | number[] | null;
|
|
435
|
+
field: string;
|
|
435
436
|
}[] | undefined;
|
|
436
437
|
model: string;
|
|
437
438
|
}, Promise<convex_server0.GenericDocument | null>>;
|
|
438
439
|
updateMany: convex_server0.RegisteredMutation<"internal", {
|
|
439
|
-
paginationOpts: {
|
|
440
|
-
id?: number;
|
|
441
|
-
endCursor?: string | null;
|
|
442
|
-
maximumRowsRead?: number;
|
|
443
|
-
maximumBytesRead?: number;
|
|
444
|
-
numItems: number;
|
|
445
|
-
cursor: string | null;
|
|
446
|
-
};
|
|
447
440
|
input: {
|
|
448
441
|
where?: {
|
|
449
442
|
connector?: "AND" | "OR" | undefined;
|
|
450
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
451
|
-
field: string;
|
|
443
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
452
444
|
value: string | number | boolean | string[] | number[] | null;
|
|
445
|
+
field: string;
|
|
453
446
|
}[] | undefined;
|
|
454
447
|
update: {
|
|
455
448
|
[x: string]: unknown;
|
|
@@ -462,6 +455,14 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>, DataModel e
|
|
|
462
455
|
update: any;
|
|
463
456
|
model: string;
|
|
464
457
|
};
|
|
458
|
+
paginationOpts: {
|
|
459
|
+
id?: number;
|
|
460
|
+
endCursor?: string | null;
|
|
461
|
+
maximumRowsRead?: number;
|
|
462
|
+
maximumBytesRead?: number;
|
|
463
|
+
numItems: number;
|
|
464
|
+
cursor: string | null;
|
|
465
|
+
};
|
|
465
466
|
}, Promise<{
|
|
466
467
|
count: number;
|
|
467
468
|
ids: any[];
|
|
@@ -474,9 +475,9 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>, DataModel e
|
|
|
474
475
|
input: {
|
|
475
476
|
where?: {
|
|
476
477
|
connector?: "AND" | "OR" | undefined;
|
|
477
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
478
|
-
field: string;
|
|
478
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
479
479
|
value: string | number | boolean | string[] | number[] | null;
|
|
480
|
+
field: string;
|
|
480
481
|
}[] | undefined;
|
|
481
482
|
update: {
|
|
482
483
|
[x: string]: unknown;
|
|
@@ -19154,26 +19155,26 @@ declare const createAuthRuntime: <DataModel extends GenericDataModel, Schema ext
|
|
|
19154
19155
|
};
|
|
19155
19156
|
}, Promise<any>>;
|
|
19156
19157
|
deleteMany: convex_server0.RegisteredMutation<"internal", {
|
|
19157
|
-
paginationOpts: {
|
|
19158
|
-
id?: number;
|
|
19159
|
-
endCursor?: string | null;
|
|
19160
|
-
maximumRowsRead?: number;
|
|
19161
|
-
maximumBytesRead?: number;
|
|
19162
|
-
numItems: number;
|
|
19163
|
-
cursor: string | null;
|
|
19164
|
-
};
|
|
19165
19158
|
input: {
|
|
19166
19159
|
where?: {
|
|
19167
19160
|
connector?: "AND" | "OR" | undefined;
|
|
19168
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
19169
|
-
field: string;
|
|
19161
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
19170
19162
|
value: string | number | boolean | string[] | number[] | null;
|
|
19163
|
+
field: string;
|
|
19171
19164
|
}[] | undefined;
|
|
19172
19165
|
model: string;
|
|
19173
19166
|
} | {
|
|
19174
19167
|
where?: any[] | undefined;
|
|
19175
19168
|
model: string;
|
|
19176
19169
|
};
|
|
19170
|
+
paginationOpts: {
|
|
19171
|
+
id?: number;
|
|
19172
|
+
endCursor?: string | null;
|
|
19173
|
+
maximumRowsRead?: number;
|
|
19174
|
+
maximumBytesRead?: number;
|
|
19175
|
+
numItems: number;
|
|
19176
|
+
cursor: string | null;
|
|
19177
|
+
};
|
|
19177
19178
|
}, Promise<{
|
|
19178
19179
|
count: number;
|
|
19179
19180
|
ids: any[];
|
|
@@ -19186,9 +19187,9 @@ declare const createAuthRuntime: <DataModel extends GenericDataModel, Schema ext
|
|
|
19186
19187
|
input: {
|
|
19187
19188
|
where?: {
|
|
19188
19189
|
connector?: "AND" | "OR" | undefined;
|
|
19189
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
19190
|
-
field: string;
|
|
19190
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
19191
19191
|
value: string | number | boolean | string[] | number[] | null;
|
|
19192
|
+
field: string;
|
|
19192
19193
|
}[] | undefined;
|
|
19193
19194
|
model: string;
|
|
19194
19195
|
} | {
|
|
@@ -19206,9 +19207,9 @@ declare const createAuthRuntime: <DataModel extends GenericDataModel, Schema ext
|
|
|
19206
19207
|
} | undefined;
|
|
19207
19208
|
where?: {
|
|
19208
19209
|
connector?: "AND" | "OR" | undefined;
|
|
19209
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
19210
|
-
field: string;
|
|
19210
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
19211
19211
|
value: string | number | boolean | string[] | number[] | null;
|
|
19212
|
+
field: string;
|
|
19212
19213
|
}[] | undefined;
|
|
19213
19214
|
paginationOpts: {
|
|
19214
19215
|
id?: number;
|
|
@@ -19225,27 +19226,19 @@ declare const createAuthRuntime: <DataModel extends GenericDataModel, Schema ext
|
|
|
19225
19226
|
select?: string[] | undefined;
|
|
19226
19227
|
where?: {
|
|
19227
19228
|
connector?: "AND" | "OR" | undefined;
|
|
19228
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
19229
|
-
field: string;
|
|
19229
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
19230
19230
|
value: string | number | boolean | string[] | number[] | null;
|
|
19231
|
+
field: string;
|
|
19231
19232
|
}[] | undefined;
|
|
19232
19233
|
model: string;
|
|
19233
19234
|
}, Promise<convex_server0.GenericDocument | null>>;
|
|
19234
19235
|
updateMany: convex_server0.RegisteredMutation<"internal", {
|
|
19235
|
-
paginationOpts: {
|
|
19236
|
-
id?: number;
|
|
19237
|
-
endCursor?: string | null;
|
|
19238
|
-
maximumRowsRead?: number;
|
|
19239
|
-
maximumBytesRead?: number;
|
|
19240
|
-
numItems: number;
|
|
19241
|
-
cursor: string | null;
|
|
19242
|
-
};
|
|
19243
19236
|
input: {
|
|
19244
19237
|
where?: {
|
|
19245
19238
|
connector?: "AND" | "OR" | undefined;
|
|
19246
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
19247
|
-
field: string;
|
|
19239
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
19248
19240
|
value: string | number | boolean | string[] | number[] | null;
|
|
19241
|
+
field: string;
|
|
19249
19242
|
}[] | undefined;
|
|
19250
19243
|
update: {
|
|
19251
19244
|
[x: string]: unknown;
|
|
@@ -19258,6 +19251,14 @@ declare const createAuthRuntime: <DataModel extends GenericDataModel, Schema ext
|
|
|
19258
19251
|
update: any;
|
|
19259
19252
|
model: string;
|
|
19260
19253
|
};
|
|
19254
|
+
paginationOpts: {
|
|
19255
|
+
id?: number;
|
|
19256
|
+
endCursor?: string | null;
|
|
19257
|
+
maximumRowsRead?: number;
|
|
19258
|
+
maximumBytesRead?: number;
|
|
19259
|
+
numItems: number;
|
|
19260
|
+
cursor: string | null;
|
|
19261
|
+
};
|
|
19261
19262
|
}, Promise<{
|
|
19262
19263
|
count: number;
|
|
19263
19264
|
ids: any[];
|
|
@@ -19270,9 +19271,9 @@ declare const createAuthRuntime: <DataModel extends GenericDataModel, Schema ext
|
|
|
19270
19271
|
input: {
|
|
19271
19272
|
where?: {
|
|
19272
19273
|
connector?: "AND" | "OR" | undefined;
|
|
19273
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
19274
|
-
field: string;
|
|
19274
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
19275
19275
|
value: string | number | boolean | string[] | number[] | null;
|
|
19276
|
+
field: string;
|
|
19276
19277
|
}[] | undefined;
|
|
19277
19278
|
update: {
|
|
19278
19279
|
[x: string]: unknown;
|
package/dist/auth/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { createAdapterFactory } from "better-auth/adapters";
|
|
|
7
7
|
import { getAuthTables } from "better-auth/db";
|
|
8
8
|
import { prop, sortBy, uniqueBy } from "remeda";
|
|
9
9
|
import { stripIndent } from "common-tags";
|
|
10
|
-
import { betterAuth } from "better-auth";
|
|
10
|
+
import { betterAuth } from "better-auth/minimal";
|
|
11
11
|
|
|
12
12
|
//#region src/auth/adapter-utils.ts
|
|
13
13
|
const adapterWhereValidator = v.object({
|
|
@@ -764,7 +764,7 @@ const adapterConfig = {
|
|
|
764
764
|
return data;
|
|
765
765
|
},
|
|
766
766
|
customTransformOutput: ({ data, fieldAttributes }) => {
|
|
767
|
-
if (data && fieldAttributes.type === "date") return new Date(data)
|
|
767
|
+
if (data && fieldAttributes.type === "date") return new Date(data);
|
|
768
768
|
return data;
|
|
769
769
|
}
|
|
770
770
|
};
|
|
@@ -1146,6 +1146,29 @@ const createDisabledAuthRuntime = (config) => {
|
|
|
1146
1146
|
|
|
1147
1147
|
//#endregion
|
|
1148
1148
|
//#region src/auth/helpers.ts
|
|
1149
|
+
const SESSION_TOKEN_COOKIE_NAME = "better-auth.session_token";
|
|
1150
|
+
const parseSessionTokenFromCookie = (cookieHeader) => {
|
|
1151
|
+
if (!cookieHeader) return null;
|
|
1152
|
+
const parts = cookieHeader.split(";");
|
|
1153
|
+
for (const rawPart of parts) {
|
|
1154
|
+
const part = rawPart.trim();
|
|
1155
|
+
const equalsIndex = part.indexOf("=");
|
|
1156
|
+
if (equalsIndex <= 0) continue;
|
|
1157
|
+
const cookieName = part.slice(0, equalsIndex);
|
|
1158
|
+
const normalizedCookieName = cookieName.startsWith("__Secure-") ? cookieName.slice(9) : cookieName;
|
|
1159
|
+
if (!(normalizedCookieName === SESSION_TOKEN_COOKIE_NAME || normalizedCookieName.endsWith(".session_token") || normalizedCookieName === "session_token")) continue;
|
|
1160
|
+
const value = part.slice(equalsIndex + 1);
|
|
1161
|
+
return value ? decodeURIComponent(value) : null;
|
|
1162
|
+
}
|
|
1163
|
+
return null;
|
|
1164
|
+
};
|
|
1165
|
+
const getCookieHeaderFromCtx = (ctx) => {
|
|
1166
|
+
const headers = (ctx?.req)?.headers;
|
|
1167
|
+
if (!headers) return null;
|
|
1168
|
+
if (headers instanceof Headers) return headers.get("cookie");
|
|
1169
|
+
const cookie = headers.cookie ?? headers.Cookie ?? headers["set-cookie"] ?? headers["Set-Cookie"];
|
|
1170
|
+
return typeof cookie === "string" ? cookie : null;
|
|
1171
|
+
};
|
|
1149
1172
|
const getAuthUserIdentity = async (ctx) => {
|
|
1150
1173
|
const identity = await ctx.auth.getUserIdentity();
|
|
1151
1174
|
if (!identity) return null;
|
|
@@ -1172,7 +1195,11 @@ async function getSession(ctx, _sessionId) {
|
|
|
1172
1195
|
}
|
|
1173
1196
|
const getHeaders = async (ctx, session) => {
|
|
1174
1197
|
const resolvedSession = session ?? await getSession(ctx);
|
|
1175
|
-
if (!resolvedSession)
|
|
1198
|
+
if (!resolvedSession) {
|
|
1199
|
+
const sessionToken = parseSessionTokenFromCookie(getCookieHeaderFromCtx(ctx));
|
|
1200
|
+
if (sessionToken) return new Headers({ authorization: `Bearer ${sessionToken}` });
|
|
1201
|
+
return new Headers();
|
|
1202
|
+
}
|
|
1176
1203
|
return new Headers({
|
|
1177
1204
|
...resolvedSession?.token ? { authorization: `Bearer ${resolvedSession.token}` } : {},
|
|
1178
1205
|
...resolvedSession?.ipAddress ? { "x-forwarded-for": resolvedSession.ipAddress } : {}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as defaultIsUnauthorized } from "../../error-Be4OcwwD.js";
|
|
2
|
-
import { t as createCallerFactory } from "../../caller-factory-
|
|
2
|
+
import { t as createCallerFactory } from "../../caller-factory-D3OuR1eI.js";
|
|
3
3
|
import { getToken } from "@convex-dev/better-auth/utils";
|
|
4
4
|
|
|
5
5
|
//#region src/auth-nextjs/index.ts
|
|
@@ -52,14 +52,19 @@ function convexBetterAuth(opts) {
|
|
|
52
52
|
api: opts.api,
|
|
53
53
|
convexSiteUrl: opts.convexSiteUrl,
|
|
54
54
|
auth: jwtCacheEnabled ? {
|
|
55
|
-
getToken: (siteUrl, headers, getTokenOpts) =>
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
getToken: (siteUrl, headers, getTokenOpts) => {
|
|
56
|
+
const mutableHeaders = new Headers(headers);
|
|
57
|
+
mutableHeaders.delete("content-length");
|
|
58
|
+
mutableHeaders.delete("transfer-encoding");
|
|
59
|
+
return getToken(siteUrl, mutableHeaders, {
|
|
60
|
+
...getTokenOpts,
|
|
61
|
+
jwtCache: {
|
|
62
|
+
enabled: true,
|
|
63
|
+
expirationToleranceSeconds: auth.expirationToleranceSeconds,
|
|
64
|
+
isAuthError: auth.isUnauthorized ?? defaultIsUnauthorized
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
},
|
|
63
68
|
isUnauthorized: auth.isUnauthorized ?? defaultIsUnauthorized
|
|
64
69
|
} : void 0
|
|
65
70
|
});
|
|
@@ -141,11 +141,14 @@ function createCallerFactory(opts) {
|
|
|
141
141
|
const isUnauthorized = opts.auth?.isUnauthorized;
|
|
142
142
|
const crpcMeta = buildMetaIndex(opts.api);
|
|
143
143
|
const callWithTokenAndRetry = async (fn, tokenResult, headers) => {
|
|
144
|
+
const shouldRetryWithFreshToken = !!opts.auth && !tokenResult.isFresh;
|
|
144
145
|
try {
|
|
145
146
|
return await fn(tokenResult.token);
|
|
146
147
|
} catch (error) {
|
|
147
|
-
if (
|
|
148
|
-
|
|
148
|
+
if (!shouldRetryWithFreshToken) {
|
|
149
|
+
if (isUnauthorized?.(error)) return null;
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
149
152
|
const newToken = await getToken(siteUrl, headers, {
|
|
150
153
|
...opts,
|
|
151
154
|
forceRefresh: true
|
package/dist/react/index.js
CHANGED
|
@@ -2103,6 +2103,12 @@ var ConvexQueryClient = class {
|
|
|
2103
2103
|
} else {
|
|
2104
2104
|
const { error } = result;
|
|
2105
2105
|
const authState = this.getAuthState();
|
|
2106
|
+
const meta = query.meta;
|
|
2107
|
+
const isUnauthorized = authState?.isUnauthorized(error) ?? false;
|
|
2108
|
+
if (isUnauthorized && meta?.skipUnauth) {
|
|
2109
|
+
this.queryClient.setQueryData(queryKey, this.transformer.output.deserialize(null));
|
|
2110
|
+
return;
|
|
2111
|
+
}
|
|
2106
2112
|
query.setState({
|
|
2107
2113
|
error,
|
|
2108
2114
|
errorUpdateCount: query.state.errorUpdateCount + 1,
|
|
@@ -2112,7 +2118,7 @@ var ConvexQueryClient = class {
|
|
|
2112
2118
|
fetchStatus: "idle",
|
|
2113
2119
|
status: "error"
|
|
2114
2120
|
}, { meta: "set by ConvexQueryClient" });
|
|
2115
|
-
if (authState?.
|
|
2121
|
+
if (isUnauthorized && authState?.isAuthenticated) {
|
|
2116
2122
|
const [, funcName] = queryKey;
|
|
2117
2123
|
authState.onUnauthorized({ queryName: funcName });
|
|
2118
2124
|
}
|
package/dist/server/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { c as isMutationCtx, d as requireActionCtx, f as requireMutationCtx, g as pick, i as addFieldsToValidator, l as isQueryCtx, m as requireRunMutationCtx, n as customCtx, o as vRequired, p as requireQueryCtx, s as isActionCtx, t as NoOp, u as isRunMutationCtx } from "../customFunctions-CZnCwoR3.js";
|
|
2
2
|
import { i as decodeWire, o as encodeWire, s as getTransformer } from "../transformer-Dh0w2py0.js";
|
|
3
|
-
import { n as createLazyCaller, r as createServerCaller, t as createCallerFactory } from "../caller-factory-
|
|
3
|
+
import { n as createLazyCaller, r as createServerCaller, t as createCallerFactory } from "../caller-factory-D3OuR1eI.js";
|
|
4
4
|
import { ConvexError, v } from "convex/values";
|
|
5
5
|
import { HttpRouter, actionGeneric, getFunctionName, httpActionGeneric, internalActionGeneric, internalMutationGeneric, internalQueryGeneric, makeFunctionReference, mutationGeneric, queryGeneric } from "convex/server";
|
|
6
6
|
import * as z$1 from "zod/v4";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-convex",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Better Convex - React Query integration and CLI tools for Convex",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"convex",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@clack/prompts": "^0.11.0",
|
|
43
|
-
"@convex-dev/better-auth": "^0.10.
|
|
43
|
+
"@convex-dev/better-auth": "^0.10.11",
|
|
44
44
|
"chokidar": "^5.0.0",
|
|
45
45
|
"common-tags": "^1.8.2",
|
|
46
46
|
"dotenv": "^17.3.1",
|