bednaz
bednaz4w ago

Use Multi Convex projects

Hey, I love convex but I was wondering if there was any best practice or advice around using mutli convex projects in a single application. For context, what I want to do is build out a private npm package that has common integration for Clerk so I don't have to keep rewriting code and setting up the integration for each app. In My use case its fine to have a central auth to connect everything. I am thinking I would just alias the env vars to for this package. When the package is all build out, I would think to make a prod setup for all this and turn it into an npm package and then reuse it in multi other projects. Along with that I would like to use a main convex folder for the specific project. This one would be in dev as normal as normal. Are there any concerns with this or any reason not to take this approach? If this is a good way approach are there any best practices or considerations around this?
6 Replies
Convex Bot
Convex Bot4w ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
deen
deen3w ago
Are you saying a client application will connect to one convex for auth, and another for regular database stuff? How will your auth convex authenticate the client for the other? However you do it, I think treating it like a public library is a good approach (even if its not) - encapsulate all of the convexy stuff, as if it could be used anywhere.
bednaz
bednazOP3w ago
That is the approach I am thinking of. Ideally all the authentication would be pointing to one convex project and all the stuff for that app would point to it's own database. I am just wondering about how convex might cause problems if there are two different endpoints be connected to. For client authentication, I would let clerk and convexes integration handle that. So when someone authenticates with clerk it calls the web hook and update the user data and does everything it needs to. I think it was in the docs if I remember correctly.
deen
deen3w ago
I've transferred/transformed data between two different convex apps, and the dev/prod env of the same app, using a simple typescript module run with bun. It works great - they don't do silly any global that would interfere with each other. I assume the browser is the same, but I haven't tried it. I think any complexity will come down to however you structure your implementation, and the Clerk side. I don't know if this what you're aiming for, but could another approach making your auth service backend only, and your app convex reaches out to that? Getting a tokenIdentifer on the convex side is simple - you just need the auth.config.ts and env var (I don't even think you need to install anything?). The app convex can reach out to your auth service with the id to find out what to do with it directly, rather than your front end having to be concerned about the dance between two convexes. Clerk is particular about domains, but I think you can just point its webhooks anywhere. I've never used a Clerk instance with more than one domain - not sure if you plan on have multiple Clerks or trying to share one. Long story short, yeah you can use multiple convex clients :convex: . I'd be interested in hearing about what you come up with.
bednaz
bednazOP3w ago
Good to know it can be done lol I am using clerk mostly because I don't want to build out all the authentication myself and feel outsourcing that would work for now. I think I have an idea around clerks domain name issue, I did read about how they updated some aspects of that recently. So hopefully that can add some flexibility but I need to look into it I have some ideas for it and I am working on designing something on it. I will let you know how it goes. This happens to be for a react native project so that makes a bit different as well. Probably should have mentioned that
deen
deen3w ago
Yeah that's why I use Clerk. I'm not sure how it differs with Native. But I would guess any challenge with making this work would be from the Clerk side. Good luck!

Did you find this page helpful?