Link app data to a user
Associate application records with the signed-in account.
Clerk · Pipe
userId identifies the current Clerk user in authentication state. Read it with useAuth() on the client, or pass it to getUser() on the backend to retrieve the full user record.
Clerk exposes userId through authentication state to identify the currently signed-in user. Check the loading state before using it, and treat a missing value as unauthenticated; when full profile data is needed, use the user-management APIs or user hook.
const { userId } = useAuth()| Name | Type | Description |
|---|---|---|
userId | string | The Clerk user identifier used to retrieve the corresponding Backend User record. |
The current authenticated user's ID when signed in; otherwise no user ID is available. The backend getUser(userId) operation returns the corresponding Backend User object.
useAuth() is the client-side entry point for reading authentication state.getUser() when backend code needs the complete user record.useUser() when the component needs the current user's broader data, not just the identifier.getUser() when you need the complete Backend User object.const { userId, isLoaded } = useAuth()
if (!isLoaded) return <p>Loading...</p>
if (!userId) return <p>Sign in to continue</p>
return <p>Signed-in user: {userId}</p>This reads the current user's identifier from Clerk's client-side authentication state after loading completes.
Associate application records with the signed-in account.
Determine whether a client session belongs to an authenticated user.
Retrieve complete user profile data on the server.
userId used for in Clerk?userId identifies the currently authenticated Clerk user. On the client, obtain it from useAuth() and check loading and authentication state before using it.
Follow-up: How would you retrieve profile details? Pass the identifier to the backend users resource's getUser(userId) method, which returns the full Backend User object.
userId in a React component?The client-side useAuth() hook exposes authentication state including userId. A missing identifier means there is no authenticated user, while a present identifier can be used to associate application data with that user.
Follow-up: What should happen while authentication state is unresolved? Render a loading state until the hook reports that it has finished loading.
userId into user data?Use the identifier with Clerk's backend client when server-side code needs user data: clerkClient.users.getUser(userId). That call retrieves the user's complete Backend User record rather than only the ID.
Follow-up: What is the key security boundary? Only perform protected retrieval after authentication has been established, and enforce authorization for the requested resource.
useAuth()useUser()clerkClientgetUser()AuthBackend User