-
I have my front end (Next.js w/ app dir) at example.com and PayloadCMS on admin.example.com. On my front end I'm using Clerk for user authentication. I'm trying to figure out the "best" way to architect both Payload and Next to seamlessly work together. In Payload I have a "Clients" collection containing all the users information. I set up hooks to automatically create/delete Clerk users and assign the clerk user Id to a read only field in the Client. The problem I'm trying to solve is how to make requests in Nextjs to Payload. I see from the docs there are two ways to integeate with third-party services/apis:
Here are my two attempts at doing each.
PayloadCMS -> clerkStrategy.ts
This is calling it from client-side, but concept should be the same if I were to use route handlers or server components.
This approach feels a lot more simple but I'm still not sure if this is the right way. Since the I'm just looking for some feedback as to the pros/cons of each approach and/or if I'm on the right track. It's a little overwhelming and I don't want to overthink it, but I also don't want to be going about this the wrong way. Any feedback is helpful. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Payload CMS with Clerk seems like a great idea. Did you end up answering your own questions and getting Clerk to work nicely with Payload? |
Beta Was this translation helpful? Give feedback.
Yes I did! My approach is probably less than ideal, but it works perfectly for what I'm doing. Ideally one would use a custom passport strategy (which I sort of had going above), but I wasn't able to fully get it. My approach has been working very well in production though:
This util will simply take the Clerk session token passed in the request auth header (or will attempt to get from cookies if no auth header) and decode/verify it using Clerk backend. (make sure
CLERK_SECRET_KEY
env variable is set).