Documentation Index
Fetch the complete documentation index at: https://mintlify.com/get-convex/better-auth/llms.txt
Use this file to discover all available pages before exploring further.
Showing UI based on authentication state
You can control which UI is shown when the user is signed in or signed out using Convex’s<Authenticated>, <Unauthenticated> and <AuthLoading> helper components. These components are powered by Convex’s useConvexAuth() hook, which provides isAuthenticated and isLoading flags. This hook can be used directly if preferred.
In the following example, the <Content /> component is a child of <Authenticated>, so its content and any of its child components are guaranteed to have an authenticated user, and Convex queries can require authentication.
src/App.tsx
Authentication state in Convex functions
If the client is authenticated, you can access the information stored in the JWT viactx.auth.getUserIdentity.
If the client is not authenticated, ctx.auth.getUserIdentity will return null.
Make sure that the component calling a query that requires authentication is a child of
<Authenticated> from convex/react, or that isAuthenticated from useConvexAuth() is true. Otherwise, it will throw on page load.Getting the current user
There are two ways to get the current user in a Convex function:authComponent.getAuthUser(ctx)
Returns the full user object with session validation. Throws if unauthenticated. Use this when you need the full user record and want to enforce authentication.
ctx.auth.getUserIdentity()
Returns the identity from the JWT without validating the session against the database. Returns
null if not authenticated. Lighter weight, but does not confirm the session is still valid.convex/messages.ts