Clerk logo

Clerk Docs

Ctrl + K
Go to clerkstage.dev

currentUser()

Access the User object inside of your server components, actions and route handlers.

The currentUser helper returns the current user allowing you to enrich your application. You can use the user object to access the currently active User.

Below is a basic example of usage, however it can be used in, server components, route handlers and server actions.

1
import { currentUser } from '@clerk/nextjs';
2
3
export default async function Home() {
4
const user = await currentUser();
5
if (!user) return <div>Not logged in</div>;
6
return <div>Hello {user?.firstName}</div>;
7
}
8

Was this helpful?

Clerk © 2023