djbalin
djbalin
CCConvex Community
Created by djbalin on 12/19/2024 in #support-community
[Backup & restore]: Force overwrite
Would it be possible to add this to the web interface restore? Maybe this could be made an option only for dev environments to avoid doing something nasty. We back up our prod deployment, and sometimes I would like to overwrite my dev deployment with such a backup, but must manually clear all tables first to avoid this error:
Hit an error while importing: _id p1703ysnrnkv5skgsshk2zaa0h76ch4j cannot be imported into 'subscription' because it came from a different deployment and conflict with preexisting tables in this deployment. Try deleting preexisting tables or importing into an empty deployment.
Hit an error while importing: _id p1703ysnrnkv5skgsshk2zaa0h76ch4j cannot be imported into 'subscription' because it came from a different deployment and conflict with preexisting tables in this deployment. Try deleting preexisting tables or importing into an empty deployment.
4 replies
CCConvex Community
Created by djbalin on 12/18/2024 in #support-community
Calling `ctx.runQuery` from `query`
I seem to have my world shaken by Convex almost every day (in a good way)! I always thought ctx.runQuery/runMutation was only possible from actions, and that calling a query from within a query was not possible, but that regular TS helper functions should be employed (e.g. as @erquhart mentions here https://discord.com/channels/1019350475847499849/1216003221445939330/1216033039247867984). I just found out that it is indeed possible by just using ctx.runQuery. That comes with this warning/info: often you can call the query's function directly? Is this what you mean/propose?:
export const getAllCategories = authQuery({
handler: async (ctx) => {
return ...
},
})

export const testQuery = authQuery({
handler: async (ctx) => {
const categories = await getAllCategories(ctx, {})
},
})
export const getAllCategories = authQuery({
handler: async (ctx) => {
return ...
},
})

export const testQuery = authQuery({
handler: async (ctx) => {
const categories = await getAllCategories(ctx, {})
},
})
4 replies
CCConvex Community
Created by djbalin on 12/5/2024 in #support-community
Union schema: no type inference?
No description
3 replies
CCConvex Community
Created by djbalin on 12/4/2024 in #support-community
Ignoring _generated in pull requests/git diff
Hey, does anybody know how to do this? It's suggested to not gitignore the _generated files for CI/CD reasons (and we concur with this), but we would still like to not have the files show up in our diffs for pull requests. We tried putting the belowin a .gitattributes file, but seems like that doesnt apply to github pull requests. Anybody have some advice for this? Thanks! 🇩🇰
/convex/_generated/* -diff
/convex/_generated/api.d.ts -diff
convex/_generated/api.d.ts -diff
/convex/_generated/* -diff
/convex/_generated/api.d.ts -diff
convex/_generated/api.d.ts -diff
7 replies
CCConvex Community
Created by djbalin on 11/29/2024 in #support-community
Bandwidth usage multiplied by piping arguments?
Hellooo! I noticed that one of my daily cron jobs is incurring rater high bandwidth usage. We have a video streaming app, and this cron job collects all watch events within the past 24 hours (using the _creationTime index) and populates three aggregates with these documents. My specific question is this: Let's say I query 1 MB worth of data and call four functions with this as an argument:
const obj = await ctx.db.query("watchSessions").collect() // 1 MB of data
fn1(obj)
fn2(obj)
fn3(obj)
fn4(obj)
const obj = await ctx.db.query("watchSessions").collect() // 1 MB of data
fn1(obj)
fn2(obj)
fn3(obj)
fn4(obj)
Would this already incur +4 MB of bandwidth usage? As far as I can tell, objects are passed by reference as arguments to functions in JS, so I suppose not? What if instead of regular JS functions, I schedule/run four Convex functions:
const obj = await ctx.db.query("watchSessions").collect() // 1 MB of data
await ctx.runMutation(api.mut1,{obj})
await ctx.runMutation(api.mut2,{obj})
await ctx.runMutation(api.mut3,{obj})
await ctx.runMutation(api.mut4,{obj})
const obj = await ctx.db.query("watchSessions").collect() // 1 MB of data
await ctx.runMutation(api.mut1,{obj})
await ctx.runMutation(api.mut2,{obj})
await ctx.runMutation(api.mut3,{obj})
await ctx.runMutation(api.mut4,{obj})
5 replies
CCConvex Community
Created by djbalin on 9/23/2024 in #support-community
Control Convex env variables output location
No description
4 replies
CCConvex Community
Created by djbalin on 9/9/2024 in #support-community
[Convex Auth]: convexAuth() causes "Type instantiation is excessively deep and possibly infinite."
We get the Type instantiation is excessively deep and possibly infinite. error on our api object whenever we export our Convex auth stuff from auth.ts, e.g. with this simple example:
import { convexAuth } from '@convex-dev/auth/server';
import { Password } from '@convex-dev/auth/providers/Password';

export const { auth, signIn, signOut, store } = convexAuth({
providers: [Password],
session: {
totalDurationMs: 1000 * 60 * 60 * 24 * 30, // 90 days
inactiveDurationMs: 1000 * 60 * 60 * 24 * 7, // 7 days
},
});
import { convexAuth } from '@convex-dev/auth/server';
import { Password } from '@convex-dev/auth/providers/Password';

export const { auth, signIn, signOut, store } = convexAuth({
providers: [Password],
session: {
totalDurationMs: 1000 * 60 * 60 * 24 * 30, // 90 days
inactiveDurationMs: 1000 * 60 * 60 * 24 * 7, // 7 days
},
});
If we remove export from the above (such that it does not occur in our Convex generated files), our api type instantiation is not excessively deep.
3 replies
CCConvex Community
Created by djbalin on 8/27/2024 in #support-community
[Convex Auth]: signIn doesn't set isAuthenticated to true immediately
Hi, as the title suggests, signIn doesn't seem to set isAuthenticated immediately after the resolution of its promise. For example, this snippet of our AuthProvider:
const { isAuthenticated, isLoading } = useConvexAuth();
const signInResult = await signIn('password', {
flow: 'email-verification',
email,
code,
});
console.log('Confirm otp, signinresult: ', signInResult);
console.log('confirm otp done. isAuthenticated: ', isAuthenticated);
const { isAuthenticated, isLoading } = useConvexAuth();
const signInResult = await signIn('password', {
flow: 'email-verification',
email,
code,
});
console.log('Confirm otp, signinresult: ', signInResult);
console.log('confirm otp done. isAuthenticated: ', isAuthenticated);
We have isAuthenticated as false even after awaiting the successful signIn. This causes our redirection to mess up, since when isLoading resolves to false, isAuthenticated is also still false despite the user having just logged in. This doesn't seem intentional - after successful signIn, the next {isLoading, isAuthenticated} pair should resolve to a truthy authentication status, no? Thank you 🙂
6 replies
CCConvex Community
Created by djbalin on 8/9/2024 in #support-community
[Convex Auth]: automatic clean-up when deleting user/authAccount?
Hi, does Convex Auth ship with a deleteUser/deleteAuthAccount functionality that automatically cleans up related documents in all the automatically generated tables such as authSessions, authVerificationCodes, authRefreshTokens etc? 🙂 I couldn't find find it in the implementation, and I suppose you leave this functionality out to allow us full control over it, but maybe a "starter" would be nice that cleans up orphaned documents in the automatically created tables 🙂
2 replies
CCConvex Community
Created by djbalin on 8/3/2024 in #support-community
[Module: server/TS]: Generic query pipelining
No description
5 replies
CCConvex Community
Created by djbalin on 7/31/2024 in #support-community
[Convex Auth]: Monorepo Expo app: "Unable to resolve @convex-dev/auth/server" ...
Hi, we're building a Turbo Monorepo Expo app and are running into the error pasted below when running the Expo dev server from our native package. The error occurs during bundling when we try to open our iOS app. Our native app in apps/native/package.json has a dependency on packages/backend as "@flimmer/backend": "*",
iOS Bundling failed 45379ms C:\Users\jgbal\Desktop\code\flimmer-monorepo\node_modules\expo-router\entry.js (1823 modules)
Unable to resolve "@convex-dev/auth/server" from "..\..\packages\backend\convex\schema.ts"
iOS Bundling failed 45379ms C:\Users\jgbal\Desktop\code\flimmer-monorepo\node_modules\expo-router\entry.js (1823 modules)
Unable to resolve "@convex-dev/auth/server" from "..\..\packages\backend\convex\schema.ts"
The iOS device error gives this information:
Unable to resolve module @convex-dev/auth/server from C:\Users\jgbal\Desktop\code\flimmer-monorepo\packages\backend\convex\schema.ts: @convex-dev/auth/server could not be found within the project or in these directories: node_modules, ..\..\node_modules
...
> 18 | import {authTables} from '@convex-dev/auth/server';
Unable to resolve module @convex-dev/auth/server from C:\Users\jgbal\Desktop\code\flimmer-monorepo\packages\backend\convex\schema.ts: @convex-dev/auth/server could not be found within the project or in these directories: node_modules, ..\..\node_modules
...
> 18 | import {authTables} from '@convex-dev/auth/server';
Thank you!
8 replies
CCConvex Community
Created by djbalin on 7/29/2024 in #support-community
Strange Doc type/inference: "[x: string]: any;, _id: Id<string>;"
Hi, we've been running into this strange problem a few different places in our repo by now and can't quite seem to figure out what's going on. Basically, sometimes, the type returned by a Doc<TableName> returns this strange thing:
{
[x: string]: any;
_id: Id<string>;
}
{
[x: string]: any;
_id: Id<string>;
}
We're in an expo/Next monorepo, and seems to work fine when inside our backend package (where Convex is), but not when we are in our native/web packages (even though we just import Doc from the generated files)
2 replies
CCConvex Community
Created by djbalin on 7/26/2024 in #support-community
Convex Auth: Error types for signUp/signIn
Hi, is there a way to know the possible types of errors that the signUp / signIn functions can throw? I want to disambiguate between error causes on the frontend. Specifically, I want to do something like:
try {
await signIn(...);
} catch (error) {
switch (error.type){
case InvalidId: alert("No user with that username found");
case InvalidPassword: alert("Incorrect password");
case TooManyAttempts: alert("Too many attempts to log in, try again in 5 minutes");
default: alert("Something went wrong, please try again")
}
try {
await signIn(...);
} catch (error) {
switch (error.type){
case InvalidId: alert("No user with that username found");
case InvalidPassword: alert("Incorrect password");
case TooManyAttempts: alert("Too many attempts to log in, try again in 5 minutes");
default: alert("Something went wrong, please try again")
}
3 replies
CCConvex Community
Created by djbalin on 7/25/2024 in #support-community
Convex Auth: Invalid key provided to SecureStore
Hi, I am facing a bug while using the otherwise great new Convex Auth library. I have followed the setup instructions in https://labs.convex.dev/auth/setup#add-authentication-tables-to-your-schema for my React Native app, and while the signUp flow seems to work (a user document gets created in my database), I get the following error regarding the SecureStore in my frontend:
Error: Invalid key provided to SecureStore. Keys must not be empty and contain only alphanumeric characters, ".", "-" and "_".
Error: Invalid key provided to SecureStore. Keys must not be empty and contain only alphanumeric characters, ".", "-" and "_".
Since the library is handling setting and reading these keys, I find it hard to debug, and have not found a solution in the documentation, here, or online. Here is my Convex provider:
import { ConvexAuthProvider } from '@convex-dev/auth/react';
import { ConvexReactClient } from 'convex/react';
import * as SecureStore from 'expo-secure-store';
const convex = new ConvexReactClient(process.env.EXPO_PUBLIC_CONVEX_URL);

const secureStorage = {
getItem: SecureStore.getItemAsync,
setItem: SecureStore.setItemAsync,
removeItem: SecureStore.deleteItemAsync,
};

export default function ConvexClientProvider({ children }: { children: React.ReactNode }) {
return (
<ConvexAuthProvider storage={secureStorage} client={convex}>
{children}
</ConvexAuthProvider>
);
}
import { ConvexAuthProvider } from '@convex-dev/auth/react';
import { ConvexReactClient } from 'convex/react';
import * as SecureStore from 'expo-secure-store';
const convex = new ConvexReactClient(process.env.EXPO_PUBLIC_CONVEX_URL);

const secureStorage = {
getItem: SecureStore.getItemAsync,
setItem: SecureStore.setItemAsync,
removeItem: SecureStore.deleteItemAsync,
};

export default function ConvexClientProvider({ children }: { children: React.ReactNode }) {
return (
<ConvexAuthProvider storage={secureStorage} client={convex}>
{children}
</ConvexAuthProvider>
);
}
3 replies
CCConvex Community
Created by djbalin on 6/25/2024 in #support-community
useQuery vs one-off query (performance, open connections, etc.)
Hello everyone. I've been thinking about the benefits/tradeoffs of useQuery vs. the imperative/one-off query (https://docs.convex.dev/client/react#one-off-queries) and would love some input. Basically: what are the performance downsides to using useQuery? Does a useQuery e.g. maintain an open network connection throughout the lifetime of its parent component? Is it better/"safer" to default to one-off queries and only opting in to useQuery when we truly need/want e.g. the reactivity or "undefined" loading state that it provides? I am asking specifically in the context of a mobile app using tab navigation: When we navigate from screen to screen using the navigation bar, the non-focused screens/components do not unmount but are kept alive in the background. I was therefore considering if absent-mindedly using useQuery in all these screens would/could lead to a lot of unnecessary open connections and/or overhead. Thank you!
6 replies