Retrieve User
Access authenticated user data on server and client.
What It Does
Shows recommended patterns to retrieve the authenticated user from the app database and expose it client-side.
When To Use
- Building private pages and layouts.
- Needing user data in client components.
Prerequisites
- Auth integration completed.
Important
This page describes the standard kit integration path; adapt app-specific paths and config names when your project differs.
How To Use
Server-side user retrieval
import { getDBClient } from '@kit/shared/server/get-db-client';
const db = await getDBClient();
const user = await db.user.require();Provide user context to client components
import { UserProvider } from '@kit/auth/shared/user';
<UserProvider user={user}>{children}</UserProvider>Read user in client component
'use client';
import { useUser } from '@kit/auth/shared/user';
export function UserBadge() {
const user = useUser();
return <span>{user.name}</span>;
}MCP Context
capability: auth_user_access
entrypoints:
- @kit/shared/server/get-db-client
- @kit/auth/shared/user (UserProvider, useUser)
inputs:
- authenticated_request_context
outputs:
- current_user_record
constraints:
- use app user table abstraction (`db.user.*`)
side_effects:
- noneAgent Recipe
- Fetch user in server layout/page.
- Redirect if auth/onboarding conditions are not met.
- Wrap subtree with
UserProviderand consume withuseUser.
Troubleshooting
useUsererrors usually mean missingUserProviderupstream.db.user.require()throwing means auth session is missing/invalid.
Related
Integration
Step-by-step auth integration for an existing web app.
User Settings
Expose auth-related account controls inside settings pages.
How is this guide?
Last updated on 3/23/2026