How can I use Clerk with Convex on NextJS13 app routes?
Any one can help?
I saw the tutorial to use Clerk + Convex on Next13, but is using pages router, I tried, but not works on app router, says router is not ready.
33 Replies
@gwilliamnn Where does it say that router is not ready?
On the browser, let me post here all the code I used, one second!
Here's our guide to using the App router, is this what you're using? https://docs.convex.dev/quickstart/nextjs
Clerk's integration with App router is a little different, I could understand these being confusing to combine.
here:
Context
Layout
Error
But! If instead use clerk nextjs, use clerk react, works...
This works fine...
💯 thanks for the repro!
Using clerk-react is the approach we've tested
BTW, I LOVED CONVEX, for now on, its my favorite serveless backend 🙂
Nice, so, will be good to but this on documentation 🙂
but wanting to use clerk-nextjs makes sense, I'll look into this
Yeah, because I don't know what feature we will gonna miss
but, another question, now, with this implementation, what change on the flow?
We installing that library in step 6 of https://docs.convex.dev/auth/clerk but we can call it out specifically there
owww, I saw now
So, just tell me if I made the correct implementation here (its another thing)
Like, I put a funciton to every new user create on clerk, create a profile on convex
So, the profile quere/mutations:
But I agree this deserves specifically mentioning, Next.js is common enough that we can have a guide specifically for Next.js + Clerk someday
and this is the api/route who will receive the webhooks events:
Every time the user is created, updated or delete, I will create the profile on the convex,
@gwilliamnn have you seen the example for this?
or on delete, I will remove
No, I made using the webhook clerk documentation, I don't know
Nice, well we can compare https://github.com/thomasballinger/convex-clerk-users-table/blob/main/convex/http.ts#L17
so one difference is that you're doing this in a Next.js API route, while the example does it with a Convex HTTP endpoint
nice, its the same logic, but instead a profile, is the entire user
yeah
i used ngrok
for my localhost receive the apis
This looks reasonable though! You're not validating the webhook request yet
Yeah, its one of the things I need to implement
and you should add some authentication to the user profile update mutation, so that it's protected from public use
good insight, thanks!
I think your approach looks good? although using a Convex HTTP endpoint might be more convenient
I will be open a lot more support,
prob, I din't had this repo before, now I will look again
My project will get a lot query relationship
So, I will need help with this soon
for now, I'm playing with convex, I will try migrate my sanity.io project to here...
Sounds good, let us know how it goes!
🙂
@gwilliamnn there are helpful posts and code examples for dealing with document relationships on Stack:
https://stack.convex.dev/relationship-structures-let-s-talk-about-schemas
Relationship Structures: Let's Talk About Schemas
In this post we’ll look at some patterns for structuring relationships in the Convex database.
Just to update this topic, the implementation with react clerk instead clerk nextjs will be problematic with app route, because app route relies on clerk nextjs helpers functions
I already got some errors
As long as you stick to client-side and client components, you should be ok. So basically don't use Next-specific Clerk integration. Would that work?
I think will, I just need first understand what the integration with clerk makes, and then take the decision
So, after reading the documentation, the use case is to has a helper context to know if the user are or not logged in and block some query/mut?
Yup!
You can protect pages that should be only accessible after log in via a client-side redirect.