Skip to content

Authentication Quick Start

Varity Team Core Contributors Updated March 2026

Add authentication to your app in under 5 minutes. No configuration required for development.

  • Email login — passwordless magic links
  • Social login — Google, Twitter, Discord, GitHub
  • Automatic accounts — created on first sign-in
  • Session management — persistent sessions, handled for you
  • Protected routes — restrict pages to signed-in users
Terminal window
npm install @varity-labs/ui-kit @varity-labs/sdk
  1. Wrap your app with the auth provider

    Add PrivyStack to your root layout. This provides authentication context to your entire app.

    app/layout.tsx
    import { PrivyStack } from '@varity-labs/ui-kit';
    export default function RootLayout({ children }) {
    return (
    <html>
    <body>
    <PrivyStack appId={process.env.NEXT_PUBLIC_PRIVY_APP_ID}>
    {children}
    </PrivyStack>
    </body>
    </html>
    );
    }
  2. Add a login button

    Use PrivyLoginButton to render a ready-made sign-in button. Use the usePrivy() hook to check auth state and sign users out.

    components/Header.tsx
    import { PrivyLoginButton, usePrivy } from '@varity-labs/ui-kit';
    export function Header() {
    const { authenticated, logout } = usePrivy();
    return (
    <header>
    {authenticated ? (
    <button onClick={logout}>Sign Out</button>
    ) : (
    <PrivyLoginButton />
    )}
    </header>
    );
    }
  3. Protect routes

    Wrap any page with PrivyProtectedRoute. Unauthenticated users are automatically redirected to sign in.

    app/dashboard/page.tsx
    import { PrivyProtectedRoute } from '@varity-labs/ui-kit';
    export default function DashboardPage() {
    return (
    <PrivyProtectedRoute>
    <Dashboard />
    </PrivyProtectedRoute>
    );
    }

That’s it. Users can now sign in with email or social accounts.

Use the usePrivy() hook anywhere in your app to read the current user.

import { usePrivy } from '@varity-labs/ui-kit';
function Profile() {
const { user, authenticated } = usePrivy();
if (!authenticated) {
return <p>Please sign in</p>;
}
return (
<div>
<p>Email: {user?.email?.address}</p>
<p>Signed in via: {user?.linkedAccounts?.[0]?.type}</p>
</div>
);
}
PropertyTypeDescription
idstringUnique user identifier
emailobjectEmail address (user.email.address)
linkedAccountsarrayAll linked login methods (email, Google, etc.)
createdAtDateWhen the account was created