Clerk logo

Clerk Docs

Ctrl + K
Go to clerkstage.dev
Check out a preview of our new docs.

useAuth()

In Next.js, use the useAuth() hook to retrieve the authentication state from within your React components.

1
import { useAuth } from '@clerk/nextjs';
2
3
const Page = () => {
4
const { isLoaded, userId, sessionId, getToken } = useAuth();
5
6
// In case the user signs out while on the page.
7
if (!isLoaded || !userId) {
8
return null;
9
}
10
11
return <div>Hello, {userId}</div>;
12
};

Props

NameTypeDescription
userIdstring

The ID of the active user, or null when signed out. In data-loaders, this is often the only piece of information needed to securely retrieve the data associated with a request.

sessionIdstring

The ID of the active session, or null when signed out. This is primarily used in audit logs to enable device-level granularity instead of user-level.

actorstring

If user impersonation is being used, this field will contain information about the impersonator.

getToken({ template?: string; })string

Retrieves a signed JWT that is structured according to the corresponding JWT template in your dashboard. If no template parameter is provided, a default Clerk session JWT is returned.

orgIdstring

A unique identifier for this organization.

orgRolestring

The role that the user will have in the organization. Valid values are admin and basic_member

orgSlugstring

The slug of the user's active organization for the current session.

claimsobject

All claims for the JWT associated with the current user

Was this helpful?

Clerk © 2023