Server Actions
Clerk provides helpers to allow you to protect your Server Actions, fetch the current user, and interact with the Clerk API.
The following guide provides examples for using Server Actions in Server Components and in Client Components.
With Server Components
Protect your Server Actions
You can use the auth()
helper to protect your server actions. This helper will return the current user's ID if they are signed in, or null
if they are not.
Accessing the current user
Current user data is important for data enrichment. You can use the currentUser()
helper to fetch the current user's data in your server actions.
With Client Components
When using Server Actions in Client Components, you need to make sure you use prop drilling to ensure that headers are available.
Protect your Server Actions
Use the following tabs to see an example of how to protect a Server Action that is used in a Client Component.
Accessing the current user
Use the following tabs to see an example of how to access the current user in a Server Action that is used in a Client Component.
Feedback
Last updated on