Skip to main content
Docs

currentUser()

Warning

For optimal performance and to avoid rate limiting, it's recommended to use the useUser() hook on the client-side when possible. Only use currentUser() when you specifically need user data in a server context.

The currentUser() helper returns the Backend UserClerk Icon object of the currently active user. It can be used in Server Components, Route Handlers, and Server Actions.

Under the hood, this helper:

Warning

The Backend UserClerk Icon object includes a privateMetadata field that should not be exposed to the frontend. Avoid passing the full user object returned by currentUser() to the frontend. Instead, pass only the specified fields you need.

app/page.tsx
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>
}

Feedback

What did you think of this content?

Last updated on