better-convex 0.2.0 → 0.2.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/auth/index.d.ts +49 -49
- package/dist/auth-client/index.js +29 -24
- package/dist/react/index.d.ts +6 -0
- package/dist/react/index.js +22 -3
- package/dist/rsc/index.js +2 -2
- package/package.json +2 -1
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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
|
-
import * as
|
|
4
|
+
import * as convex_server0 from "convex/server";
|
|
5
5
|
import { DocumentByName, FunctionReference, GenericDataModel, GenericMutationCtx, GenericQueryCtx, GenericSchema, HttpRouter, IdField, PaginationOptions, PaginationResult, SchemaDefinition, SystemFields, TableNamesInDataModel, internalMutationGeneric } from "convex/server";
|
|
6
6
|
import * as convex_values0 from "convex/values";
|
|
7
7
|
import { Infer } from "convex/values";
|
|
@@ -44,31 +44,31 @@ 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
|
-
beforeCreate:
|
|
50
|
+
beforeCreate: convex_server0.RegisteredMutation<"internal", {
|
|
51
51
|
data: any;
|
|
52
52
|
model: string;
|
|
53
53
|
}, Promise<any>>;
|
|
54
|
-
beforeDelete:
|
|
54
|
+
beforeDelete: convex_server0.RegisteredMutation<"internal", {
|
|
55
55
|
model: string;
|
|
56
56
|
doc: any;
|
|
57
57
|
}, Promise<any>>;
|
|
58
|
-
beforeUpdate:
|
|
58
|
+
beforeUpdate: convex_server0.RegisteredMutation<"internal", {
|
|
59
59
|
update: any;
|
|
60
60
|
model: string;
|
|
61
61
|
doc: any;
|
|
62
62
|
}, Promise<any>>;
|
|
63
|
-
onCreate:
|
|
63
|
+
onCreate: convex_server0.RegisteredMutation<"internal", {
|
|
64
64
|
model: string;
|
|
65
65
|
doc: any;
|
|
66
66
|
}, Promise<void>>;
|
|
67
|
-
onDelete:
|
|
67
|
+
onDelete: convex_server0.RegisteredMutation<"internal", {
|
|
68
68
|
model: string;
|
|
69
69
|
doc: any;
|
|
70
70
|
}, Promise<void>>;
|
|
71
|
-
onUpdate:
|
|
71
|
+
onUpdate: convex_server0.RegisteredMutation<"internal", {
|
|
72
72
|
model: string;
|
|
73
73
|
newDoc: any;
|
|
74
74
|
oldDoc: any;
|
|
@@ -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,7 +159,7 @@ 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<{
|
|
@@ -175,18 +175,18 @@ declare const adapterWhereValidator: convex_values0.VObject<{
|
|
|
175
175
|
}, "required", "operator" | "value" | "field" | "connector">;
|
|
176
176
|
declare const adapterArgsValidator: convex_values0.VObject<{
|
|
177
177
|
limit?: number | undefined;
|
|
178
|
+
offset?: number | undefined;
|
|
179
|
+
select?: string[] | undefined;
|
|
180
|
+
sortBy?: {
|
|
181
|
+
field: string;
|
|
182
|
+
direction: "asc" | "desc";
|
|
183
|
+
} | undefined;
|
|
178
184
|
where?: {
|
|
179
185
|
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
180
186
|
connector?: "AND" | "OR" | undefined;
|
|
181
187
|
value: string | number | boolean | string[] | number[] | null;
|
|
182
188
|
field: string;
|
|
183
189
|
}[] | undefined;
|
|
184
|
-
select?: string[] | undefined;
|
|
185
|
-
offset?: number | undefined;
|
|
186
|
-
sortBy?: {
|
|
187
|
-
field: string;
|
|
188
|
-
direction: "asc" | "desc";
|
|
189
|
-
} | undefined;
|
|
190
190
|
model: string;
|
|
191
191
|
}, {
|
|
192
192
|
limit: convex_values0.VFloat64<number | undefined, "optional">;
|
|
@@ -216,7 +216,7 @@ declare const adapterArgsValidator: convex_values0.VObject<{
|
|
|
216
216
|
operator: convex_values0.VUnion<"eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "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
218
|
}, "required", "operator" | "value" | "field" | "connector">, "optional">;
|
|
219
|
-
}, "required", "limit" | "
|
|
219
|
+
}, "required", "limit" | "model" | "offset" | "select" | "sortBy" | "where" | "sortBy.field" | "sortBy.direction">;
|
|
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>;
|
|
@@ -244,7 +244,7 @@ declare const findOneHandler: (ctx: any, args: {
|
|
|
244
244
|
model: string;
|
|
245
245
|
select?: string[];
|
|
246
246
|
where?: any[];
|
|
247
|
-
}, schema: Schema, betterAuthSchema: any) => Promise<
|
|
247
|
+
}, schema: Schema, betterAuthSchema: any) => Promise<convex_server0.GenericDocument | null>;
|
|
248
248
|
declare const findManyHandler: (ctx: any, args: {
|
|
249
249
|
model: string;
|
|
250
250
|
paginationOpts: any;
|
|
@@ -255,7 +255,7 @@ declare const findManyHandler: (ctx: any, args: {
|
|
|
255
255
|
field: string;
|
|
256
256
|
};
|
|
257
257
|
where?: any[];
|
|
258
|
-
}, schema: Schema, betterAuthSchema: any) => Promise<
|
|
258
|
+
}, schema: Schema, betterAuthSchema: any) => Promise<convex_server0.PaginationResult<convex_server0.GenericDocument>>;
|
|
259
259
|
declare const updateOneHandler: (ctx: any, args: {
|
|
260
260
|
input: {
|
|
261
261
|
model: string;
|
|
@@ -278,8 +278,8 @@ declare const updateManyHandler: (ctx: any, args: {
|
|
|
278
278
|
count: number;
|
|
279
279
|
ids: any[];
|
|
280
280
|
isDone: boolean;
|
|
281
|
-
continueCursor:
|
|
282
|
-
splitCursor?:
|
|
281
|
+
continueCursor: convex_server0.Cursor;
|
|
282
|
+
splitCursor?: convex_server0.Cursor | null;
|
|
283
283
|
pageStatus?: "SplitRecommended" | "SplitRequired" | null;
|
|
284
284
|
}>;
|
|
285
285
|
declare const deleteOneHandler: (ctx: any, args: {
|
|
@@ -290,7 +290,7 @@ declare const deleteOneHandler: (ctx: any, args: {
|
|
|
290
290
|
beforeDeleteHandle?: string;
|
|
291
291
|
skipBeforeHooks?: boolean;
|
|
292
292
|
onDeleteHandle?: string;
|
|
293
|
-
}, schema: Schema, betterAuthSchema: any) => Promise<
|
|
293
|
+
}, schema: Schema, betterAuthSchema: any) => Promise<convex_server0.GenericDocument | undefined>;
|
|
294
294
|
declare const deleteManyHandler: (ctx: any, args: {
|
|
295
295
|
input: {
|
|
296
296
|
model: string;
|
|
@@ -304,8 +304,8 @@ declare const deleteManyHandler: (ctx: any, args: {
|
|
|
304
304
|
count: number;
|
|
305
305
|
ids: any[];
|
|
306
306
|
isDone: boolean;
|
|
307
|
-
continueCursor:
|
|
308
|
-
splitCursor?:
|
|
307
|
+
continueCursor: convex_server0.Cursor;
|
|
308
|
+
splitCursor?: convex_server0.Cursor | null;
|
|
309
309
|
pageStatus?: "SplitRecommended" | "SplitRequired" | null;
|
|
310
310
|
}>;
|
|
311
311
|
declare const createApi: <Schema$1 extends SchemaDefinition<any, any>>(schema: Schema$1, createAuth: CreateAuth, options?: {
|
|
@@ -313,7 +313,7 @@ declare const createApi: <Schema$1 extends SchemaDefinition<any, any>>(schema: S
|
|
|
313
313
|
/** Skip input validation for smaller generated types. Since these are internal functions, validation is optional. */
|
|
314
314
|
skipValidation?: boolean;
|
|
315
315
|
}) => {
|
|
316
|
-
create:
|
|
316
|
+
create: convex_server0.RegisteredMutation<"internal", {
|
|
317
317
|
select?: string[] | undefined;
|
|
318
318
|
beforeCreateHandle?: string | undefined;
|
|
319
319
|
onCreateHandle?: string | undefined;
|
|
@@ -329,7 +329,7 @@ declare const createApi: <Schema$1 extends SchemaDefinition<any, any>>(schema: S
|
|
|
329
329
|
model: string;
|
|
330
330
|
};
|
|
331
331
|
}, Promise<any>>;
|
|
332
|
-
deleteMany:
|
|
332
|
+
deleteMany: convex_server0.RegisteredMutation<"internal", {
|
|
333
333
|
beforeDeleteHandle?: string | undefined;
|
|
334
334
|
onDeleteHandle?: string | undefined;
|
|
335
335
|
paginationOpts: {
|
|
@@ -356,11 +356,11 @@ declare const createApi: <Schema$1 extends SchemaDefinition<any, any>>(schema: S
|
|
|
356
356
|
count: number;
|
|
357
357
|
ids: any[];
|
|
358
358
|
isDone: boolean;
|
|
359
|
-
continueCursor:
|
|
360
|
-
splitCursor?:
|
|
359
|
+
continueCursor: convex_server0.Cursor;
|
|
360
|
+
splitCursor?: convex_server0.Cursor | null;
|
|
361
361
|
pageStatus?: "SplitRecommended" | "SplitRequired" | null;
|
|
362
362
|
}>>;
|
|
363
|
-
deleteOne:
|
|
363
|
+
deleteOne: convex_server0.RegisteredMutation<"internal", {
|
|
364
364
|
beforeDeleteHandle?: string | undefined;
|
|
365
365
|
onDeleteHandle?: string | undefined;
|
|
366
366
|
input: {
|
|
@@ -375,21 +375,21 @@ declare const createApi: <Schema$1 extends SchemaDefinition<any, any>>(schema: S
|
|
|
375
375
|
}[] | undefined;
|
|
376
376
|
model: string;
|
|
377
377
|
};
|
|
378
|
-
}, Promise<
|
|
379
|
-
findMany:
|
|
380
|
-
limit?: number | undefined;
|
|
378
|
+
}, Promise<convex_server0.GenericDocument | undefined>>;
|
|
379
|
+
findMany: convex_server0.RegisteredQuery<"internal", {
|
|
381
380
|
join?: any;
|
|
381
|
+
limit?: number | undefined;
|
|
382
|
+
offset?: number | undefined;
|
|
383
|
+
sortBy?: {
|
|
384
|
+
field: string;
|
|
385
|
+
direction: "asc" | "desc";
|
|
386
|
+
} | undefined;
|
|
382
387
|
where?: {
|
|
383
388
|
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
384
389
|
connector?: "AND" | "OR" | undefined;
|
|
385
390
|
value: string | number | boolean | string[] | number[] | null;
|
|
386
391
|
field: string;
|
|
387
392
|
}[] | undefined;
|
|
388
|
-
offset?: number | undefined;
|
|
389
|
-
sortBy?: {
|
|
390
|
-
field: string;
|
|
391
|
-
direction: "asc" | "desc";
|
|
392
|
-
} | undefined;
|
|
393
393
|
paginationOpts: {
|
|
394
394
|
id?: number;
|
|
395
395
|
endCursor?: string | null;
|
|
@@ -399,19 +399,19 @@ declare const createApi: <Schema$1 extends SchemaDefinition<any, any>>(schema: S
|
|
|
399
399
|
cursor: string | null;
|
|
400
400
|
};
|
|
401
401
|
model: string;
|
|
402
|
-
}, Promise<
|
|
403
|
-
findOne:
|
|
402
|
+
}, Promise<convex_server0.PaginationResult<convex_server0.GenericDocument>>>;
|
|
403
|
+
findOne: convex_server0.RegisteredQuery<"internal", {
|
|
404
404
|
join?: any;
|
|
405
|
+
select?: string[] | undefined;
|
|
405
406
|
where?: {
|
|
406
407
|
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
407
408
|
connector?: "AND" | "OR" | undefined;
|
|
408
409
|
value: string | number | boolean | string[] | number[] | null;
|
|
409
410
|
field: string;
|
|
410
411
|
}[] | undefined;
|
|
411
|
-
select?: string[] | undefined;
|
|
412
412
|
model: string;
|
|
413
|
-
}, Promise<
|
|
414
|
-
updateMany:
|
|
413
|
+
}, Promise<convex_server0.GenericDocument | null>>;
|
|
414
|
+
updateMany: convex_server0.RegisteredMutation<"internal", {
|
|
415
415
|
beforeUpdateHandle?: string | undefined;
|
|
416
416
|
onUpdateHandle?: string | undefined;
|
|
417
417
|
paginationOpts: {
|
|
@@ -444,11 +444,11 @@ declare const createApi: <Schema$1 extends SchemaDefinition<any, any>>(schema: S
|
|
|
444
444
|
count: number;
|
|
445
445
|
ids: any[];
|
|
446
446
|
isDone: boolean;
|
|
447
|
-
continueCursor:
|
|
448
|
-
splitCursor?:
|
|
447
|
+
continueCursor: convex_server0.Cursor;
|
|
448
|
+
splitCursor?: convex_server0.Cursor | null;
|
|
449
449
|
pageStatus?: "SplitRecommended" | "SplitRequired" | null;
|
|
450
450
|
}>>;
|
|
451
|
-
updateOne:
|
|
451
|
+
updateOne: convex_server0.RegisteredMutation<"internal", {
|
|
452
452
|
beforeUpdateHandle?: string | undefined;
|
|
453
453
|
onUpdateHandle?: string | undefined;
|
|
454
454
|
input: {
|
|
@@ -470,8 +470,8 @@ declare const createApi: <Schema$1 extends SchemaDefinition<any, any>>(schema: S
|
|
|
470
470
|
model: string;
|
|
471
471
|
};
|
|
472
472
|
}, Promise<any>>;
|
|
473
|
-
getLatestJwks:
|
|
474
|
-
rotateKeys:
|
|
473
|
+
getLatestJwks: convex_server0.RegisteredAction<"internal", {}, Promise<any>>;
|
|
474
|
+
rotateKeys: convex_server0.RegisteredAction<"internal", {}, Promise<any>>;
|
|
475
475
|
};
|
|
476
476
|
//#endregion
|
|
477
477
|
//#region src/auth/helpers.d.ts
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { _ as defaultIsUnauthorized, d as useAuthStore, f as useAuthValue, g as CRPCClientError, r as FetchAccessTokenContext, s as decodeJwtExp, t as AuthProvider } from "../auth-store-BMSJFMtR.js";
|
|
3
3
|
import { c } from "react/compiler-runtime";
|
|
4
4
|
import { ConvexProviderWithAuth, useConvexAuth } from "convex/react";
|
|
5
|
-
import { useCallback, useEffect,
|
|
5
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
6
6
|
import { jsx } from "react/jsx-runtime";
|
|
7
7
|
|
|
8
8
|
//#region src/auth-client/convex-auth-provider.tsx
|
|
@@ -85,9 +85,26 @@ function _temp() {}
|
|
|
85
85
|
function ConvexAuthProviderInner({ children, client, authClient }) {
|
|
86
86
|
const authStore = useAuthStore();
|
|
87
87
|
const { data: session, isPending } = authClient.useSession();
|
|
88
|
+
const sessionRef = useRef(session);
|
|
89
|
+
const isPendingRef = useRef(isPending);
|
|
90
|
+
sessionRef.current = session;
|
|
91
|
+
isPendingRef.current = isPending;
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
if (!session && !isPending) {
|
|
94
|
+
authStore.set("token", null);
|
|
95
|
+
authStore.set("expiresAt", null);
|
|
96
|
+
authStore.set("isAuthenticated", false);
|
|
97
|
+
}
|
|
98
|
+
}, [
|
|
99
|
+
session,
|
|
100
|
+
isPending,
|
|
101
|
+
authStore
|
|
102
|
+
]);
|
|
88
103
|
const fetchAccessToken = useCallback(async ({ forceRefreshToken = false } = {}) => {
|
|
89
|
-
|
|
90
|
-
|
|
104
|
+
const currentSession = sessionRef.current;
|
|
105
|
+
const currentIsPending = isPendingRef.current;
|
|
106
|
+
if (!currentSession) {
|
|
107
|
+
if (!currentIsPending) {
|
|
91
108
|
authStore.set("token", null);
|
|
92
109
|
authStore.set("expiresAt", null);
|
|
93
110
|
}
|
|
@@ -106,30 +123,18 @@ function ConvexAuthProviderInner({ children, client, authClient }) {
|
|
|
106
123
|
authStore.set("expiresAt", exp);
|
|
107
124
|
}
|
|
108
125
|
return jwt;
|
|
109
|
-
} catch {
|
|
126
|
+
} catch (e) {
|
|
127
|
+
console.error("[fetchAccessToken] error", e);
|
|
110
128
|
return null;
|
|
111
129
|
}
|
|
112
|
-
}, [
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
]);
|
|
118
|
-
const useAuth = useMemo(() => function useConvexAuthHook() {
|
|
119
|
-
return useMemo(() => ({
|
|
120
|
-
isLoading: isPending,
|
|
121
|
-
isAuthenticated: session !== null,
|
|
122
|
-
fetchAccessToken
|
|
123
|
-
}), [
|
|
124
|
-
isPending,
|
|
125
|
-
session,
|
|
130
|
+
}, [authStore, authClient]);
|
|
131
|
+
const useAuth = useCallback(function useConvexAuthHook() {
|
|
132
|
+
return {
|
|
133
|
+
isLoading: isPendingRef.current,
|
|
134
|
+
isAuthenticated: sessionRef.current !== null,
|
|
126
135
|
fetchAccessToken
|
|
127
|
-
|
|
128
|
-
}, [
|
|
129
|
-
isPending,
|
|
130
|
-
session,
|
|
131
|
-
fetchAccessToken
|
|
132
|
-
]);
|
|
136
|
+
};
|
|
137
|
+
}, [fetchAccessToken]);
|
|
133
138
|
return /* @__PURE__ */ jsx(FetchAccessTokenContext.Provider, {
|
|
134
139
|
value: fetchAccessToken,
|
|
135
140
|
children: /* @__PURE__ */ jsx(ConvexProviderWithAuth, {
|
package/dist/react/index.d.ts
CHANGED
|
@@ -256,6 +256,12 @@ declare class ConvexQueryClient {
|
|
|
256
256
|
updateAuthStore(authStore?: AuthStore): void;
|
|
257
257
|
/** Get current auth state from store */
|
|
258
258
|
private getAuthState;
|
|
259
|
+
/**
|
|
260
|
+
* Check if subscription should be skipped due to auth state.
|
|
261
|
+
* Needed for useSuspenseQuery which ignores enabled: false.
|
|
262
|
+
* Regular useQuery already handles this via enabled: false in hooks.
|
|
263
|
+
*/
|
|
264
|
+
private shouldSkipSubscription;
|
|
259
265
|
/** Get QueryClient, throwing if not connected */
|
|
260
266
|
get queryClient(): QueryClient;
|
|
261
267
|
/**
|
package/dist/react/index.js
CHANGED
|
@@ -1203,6 +1203,7 @@ function createAuthMutations(authClient) {
|
|
|
1203
1203
|
return {
|
|
1204
1204
|
...options,
|
|
1205
1205
|
mutationFn: async (args) => {
|
|
1206
|
+
authStoreApi.set("isAuthenticated", false);
|
|
1206
1207
|
convexQueryClient?.unsubscribeAuthQueries();
|
|
1207
1208
|
const res = await authClient.signOut(args);
|
|
1208
1209
|
await waitForTokenClear(authStoreApi);
|
|
@@ -1451,6 +1452,18 @@ var ConvexQueryClient = class {
|
|
|
1451
1452
|
isUnauthorized: this.authStore.get("isUnauthorized")
|
|
1452
1453
|
};
|
|
1453
1454
|
}
|
|
1455
|
+
/**
|
|
1456
|
+
* Check if subscription should be skipped due to auth state.
|
|
1457
|
+
* Needed for useSuspenseQuery which ignores enabled: false.
|
|
1458
|
+
* Regular useQuery already handles this via enabled: false in hooks.
|
|
1459
|
+
*/
|
|
1460
|
+
shouldSkipSubscription(authType) {
|
|
1461
|
+
if (!authType || !this.authStore) return false;
|
|
1462
|
+
const authState = this.getAuthState();
|
|
1463
|
+
if (authState?.isLoading) return true;
|
|
1464
|
+
if (authType === "required" && !authState?.isAuthenticated) return true;
|
|
1465
|
+
return false;
|
|
1466
|
+
}
|
|
1454
1467
|
/** Get QueryClient, throwing if not connected */
|
|
1455
1468
|
get queryClient() {
|
|
1456
1469
|
if (!this._queryClient) throw new Error("ConvexQueryClient not connected to TanStack QueryClient.");
|
|
@@ -1587,9 +1600,11 @@ var ConvexQueryClient = class {
|
|
|
1587
1600
|
break;
|
|
1588
1601
|
}
|
|
1589
1602
|
case "added": {
|
|
1590
|
-
|
|
1603
|
+
const meta = event.query.meta;
|
|
1604
|
+
if (meta?.subscribe === false) break;
|
|
1591
1605
|
const [, funcName, args] = event.query.queryKey;
|
|
1592
1606
|
if (event.query.getObserversCount() === 0) break;
|
|
1607
|
+
if (this.shouldSkipSubscription(meta?.authType)) break;
|
|
1593
1608
|
const watch = this.convexClient.watchQuery(funcName, args);
|
|
1594
1609
|
const unsubscribe = watch.onUpdate(() => {
|
|
1595
1610
|
this.onUpdateQueryKeyHash(event.query.queryHash);
|
|
@@ -1609,8 +1624,10 @@ var ConvexQueryClient = class {
|
|
|
1609
1624
|
}
|
|
1610
1625
|
if (this.subscriptions[event.query.queryHash]) break;
|
|
1611
1626
|
if (event.query.options.enabled === false) break;
|
|
1612
|
-
|
|
1627
|
+
const meta = event.query.meta;
|
|
1628
|
+
if (meta?.subscribe === false) break;
|
|
1613
1629
|
const [, funcName, args] = event.query.queryKey;
|
|
1630
|
+
if (this.shouldSkipSubscription(meta?.authType)) break;
|
|
1614
1631
|
const watch = this.convexClient.watchQuery(funcName, args);
|
|
1615
1632
|
const unsubscribe = watch.onUpdate(() => {
|
|
1616
1633
|
this.onUpdateQueryKeyHash(event.query.queryHash);
|
|
@@ -1650,8 +1667,10 @@ var ConvexQueryClient = class {
|
|
|
1650
1667
|
break;
|
|
1651
1668
|
}
|
|
1652
1669
|
if (isSubscribed || isDisabled) break;
|
|
1653
|
-
|
|
1670
|
+
const meta = event.query.meta;
|
|
1671
|
+
if (meta?.subscribe === false) break;
|
|
1654
1672
|
const [, funcName, args] = event.query.queryKey;
|
|
1673
|
+
if (this.shouldSkipSubscription(meta?.authType)) break;
|
|
1655
1674
|
const watch = this.convexClient.watchQuery(funcName, args);
|
|
1656
1675
|
const unsubscribe = watch.onUpdate(() => {
|
|
1657
1676
|
this.onUpdateQueryKeyHash(event.query.queryHash);
|
package/dist/rsc/index.js
CHANGED
|
@@ -216,7 +216,7 @@ function getServerQueryClientOptions({ getToken, convexSiteUrl } = {}) {
|
|
|
216
216
|
const routeMeta = meta;
|
|
217
217
|
if (!convexSiteUrl) throw new Error("convexSiteUrl required for HTTP queries. Pass it to getServerQueryClientOptions().");
|
|
218
218
|
if (!routeMeta?.path) throw new Error(`HTTP route metadata missing for: ${routeKey}`);
|
|
219
|
-
return fetchHttpRoute(convexSiteUrl, routeMeta, args$1, token);
|
|
219
|
+
return await fetchHttpRoute(convexSiteUrl, routeMeta, args$1, token);
|
|
220
220
|
}
|
|
221
221
|
const [funcRef, args] = rest;
|
|
222
222
|
const queryMeta = meta;
|
|
@@ -224,7 +224,7 @@ function getServerQueryClientOptions({ getToken, convexSiteUrl } = {}) {
|
|
|
224
224
|
const authRequired = queryMeta?.authType === "required";
|
|
225
225
|
if (!token && (skipUnauth || authRequired)) return null;
|
|
226
226
|
const opts = token ? { token } : void 0;
|
|
227
|
-
return type === "convexQuery" ? fetchQuery(funcRef, args, opts) : fetchAction(funcRef, args, opts);
|
|
227
|
+
return type === "convexQuery" ? await fetchQuery(funcRef, args, opts) : await fetchAction(funcRef, args, opts);
|
|
228
228
|
},
|
|
229
229
|
queryKeyHashFn: createHashFn()
|
|
230
230
|
} };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-convex",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Better Convex - React Query integration and CLI tools for Convex",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"convex",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"chokidar": "^5.0.0",
|
|
39
39
|
"common-tags": "^1.8.2",
|
|
40
|
+
"dotenv": "^17.2.3",
|
|
40
41
|
"execa": "^9.6.1",
|
|
41
42
|
"jiti": "^2.6.1",
|
|
42
43
|
"jotai-x": "^2.3.3",
|