Render server-side profile data
A Server Component needs to render the signed-in user's name or other server-fetched profile data.
Clerk · Function
currentUser() asynchronously returns the Backend User for the currently active user in a Next.js App Router server context. Use it in Server Components, Route Handlers, or Server Actions when server-side user data is needed.
In a Next.js App Router server context, await currentUser() to fetch the Backend User for the currently active session. The helper can run in Server Components, Route Handlers, and Server Actions; it uses the Backend API and returns null when no active user is available.
await currentUser()Promise<Backend User | null>
import { currentUser } from '@clerk/nextjs/server'
export default async function Page() {
const user = await currentUser()
if (!user) return <div>Not signed in</div>
return <div>Hello {user.firstName}</div>
}Fetches the active Backend User in a Next.js Server Component and renders a selected field only when a user is signed in.
A Server Component needs to render the signed-in user's name or other server-fetched profile data.
A Route Handler needs selected identity fields to construct an authenticated response.
A Server Action needs the active Backend User while processing a server-side mutation.
currentUser() returns the Backend User object for the currently active user. It is asynchronous because it fetches the user through Clerk's Backend API.
Follow-up: How would you reduce unnecessary requests for client-rendered profile data? Use the useUser() hook on the client instead of currentUser() when server-side access is not required.
It can be used in Next.js Server Components, Route Handlers, and Server Actions. In each case, await the helper and handle the no-user result before reading user fields.
Follow-up: What must be true when invoking it from a Server Action called by a Client Component? The action must receive the available server request context through the supported server-side invocation pattern, because the helper needs request headers.
The helper calls Clerk's GET /v1/users/{user_id} endpoint and its request counts against the Backend API rate limit. It is also automatically deduplicated per request because it uses fetch().
Follow-up: What should an endpoint return to the browser? Select only required fields, such as id or firstName, rather than forwarding the entire Backend User object.
useUser()auth()clerkClient()Backend UserServer ComponentsRoute HandlersServer Actions