FeaturesAuthentication
PreviousNext

Retrieve User

Retrieve the current user in your application.

Once the user is logged in, you will have to get the user data in your application. For this you will have to use the @kit/auth/user endpoint that expose all the tools you need for post-authentication actions.

Server

'server-only';
 
import { getDrizzleSupabaseClient } from '@kit/db';
import { getSupabaseServerClient } from '@kit/supabase-server';
 
async function () {
    const supabaseClient = getSupabaseServerClient();
    const db = await getDrizzleSupabaseClient(supabaseClient);
 
    const user = await db.user.get();
};
 

Client

User Provider

The first thing you will have to do is to wrap your application with the UserProvider component.

app/dashboard/layout.tsx
import React from 'react'; import { UserProvider } from '@kit/auth/user'; import { redirect } from 'next/navigation'; import { getDBClient } from '~/lib/get-db-client'; export default async function YourPrivateEndpointLayout( props: React.PropsWithChildren ): Promise<React.JSX.Element> { const db = await getDBClient(); const user = await db.user.get(); if (!user) { return redirect('/auth/sign-in'); } if (!user.completedOnboarding) { return redirect('/onboarding'); } return <UserProvider user={user}>{props.children}</UserProvider>; }

User Hook

Use the useUser hook to access the current authenticated user:

'use client'; import { useUser } from '@kit/auth/user'; export function UserProfile() { const user = useUser(); if (!user) { return <div>Please sign in</div>; } return ( <div> <h1>Welcome, {user.name}</h1> <p>Email: {user.email}</p> </div> ); }

Sign Out Button

Add a sign out button using the provided component:

'use client';
 
import { SignOutButton } from '@kit/auth/ui/sign-out-button';
import { authConfig } from '~/config/auth.config';
 
export function Header() {
    return (
        <header>
            <nav>
                {/* Other nav items */}
                <SignOutButton redirectTo={authConfig.urls.signIn} />
            </nav>
        </header>
    );
}

SignOutButtonProps

PropTypeDefault
redirectTo*
string
onSignOut
function
asChild
boolean
false

Next Steps

In the next page, you will see how to display the authentication user settings.

PageDescription
Session ManagementView and manage active user sessions
MFA SecurityEnable two-factor authentication
Account DeletionDelete a user account

How is this guide?

Last updated on 10/17/2025