Need a little push in the right direction. So I got this all working (Clerk users in my db with roles and memberships) What would be the best way to check the current user (incl. their role/membership, which are stored in my database)? Wrap the app with my own context? But use context is client side only. Hmm...still so new, huge gaps in my knowledge
I would use Clerk's helper function to check the current user. For instance, on the server, auth() and currentUser() are App Router-specific helpers. You can also use the `useAuth` hook on client-side. Here is a link to the docs for further reading → clerk.com/docs/references/nextjs/read-session-data
Thanks for the video, Hamed! I encountered an issue. When using the middleware provided in the tutorial, after signing out, the site redirects me directly to the login page. I need it to display the components I've created for the logged-out state. Do you know how to resolve this?
Great video. I’ve been struggling with this. Wasn’t sure if I should use the clerk Id as my unique user identifier in the database or something like the token Id. Wanted to make sure it was an id that would not potentially change on the clerk side. I am doing this with my Convex backend and seems to be very fast and reliable.
@@hamedbahram I really tried to avoid Convex for a while, but curiousity got the best of me. I now use it for all my projects. The dev experience has been so nice and it intigrates well with Clerk. I had to rethink some things as I used to use prisma and other relational db’s, but it’s very powerful.
Hi sir, I think the only issue I faced for this is this is a one way sync. If I send a put request to modify the user data in mongodb it will not affect the data in clerk. How do you ensure single source of truth?
You can update Clerk using the backend sdk so it's in sync whenever you make updates to your database. That said, it's not necessary to sync everything with Clerk, only things that would be useful in your app to have on the session perhaps.
Good question! You can use Clerk's backend API to programatically add a user to blocklist. You can read more here → clerk.com/docs/reference/backend-api/tag/Allow-list-Block-list#operation/CreateBlocklistIdentifier
i got error: Error: Base64Coder: incorrect padding at Coder._getPaddingLength (webpack-internal:///(rsc)/../../../node_modules/@stablelib/base64/lib/base64.js:199:23) at Coder.decode (webpack-internal:///(rsc)/../../../node_modules/@stablelib/base64/lib/base64.js:80:34) at Object.decode (webpack-internal:///(rsc)/../../../node_modules/@stablelib/base64/lib/base64.js:213:21) at new Webhook (webpack-internal:///(rsc)/../../../node_modules/svix/dist/index.js:405:31) at POST (webpack-internal:///(rsc)/./src/app/api/webhooks/test/route.ts:30:16) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) .... POST /api/webhooks/test 500 in 59ms Can you help me?
I was getting the same error and I figured it out. In the Clerk documentation, it tells you to paste the webhook signing secret into your .env.local file, but for some reason, the documentation does not auto-populate your real webhook signing secret (unlike other places in the Clerk documentation). The wrong one looks like this: WEBHOOK_SECRET=whsec_123 Your real webhook signing secret is located in the Webhooks page of your Clerk dashboard inside your clerk endpoint. Hope this helps