Use Clerk `getAuth(req)` in a Zact server action
Is there a way to get the Next request object in a Zact server action.
I require this to be able to get the current user using Clerk's
getAuth
functionSolution:Jump to solution
You gotta do action > server > client because action -> client doesn't support headers yet
9 Replies
Also interested in this
If you use auth() we pull the headers... getAuth doesn't. Server actions which is what Zact is layering you can find how to use server actions right here. Using the App router specific built features.
https://clerk.com/docs/nextjs/server-actions
Server Actions | Clerk
Learn how to use Clerk with Next.js Server Actions
Ahh cheers, although I'm getting this error:
You trying to use a server action directly in a client component?
Yeah I'm calling it in a client component
Do I need to pass down the action as a prop from my server components to client components like in the code example?
Solution
You gotta do action > server > client because action -> client doesn't support headers yet
sorry do you mind elaborating on this?
i'm calling a server action from my client component but clerk is yelling at me with the same "auth() are only supported in app router"
yup headers aren’t available in a client components so you have to do what’s described in our docs
https://clerk.com/docs/nextjs/server-actions#with-client-components
prop drill to your client component
Server Actions | Clerk
Learn how to use Clerk with Next.js Server Actions
So i'm trying to create a context with zact server actions
And then i import this into my action
And then i prop drill the action into my client component and it still errors out. Is this not allowed?