Ready-to-use authentication components for sign-in, user menus, and session management
NOW.TS comes with all the components you need to easily manage authentication. They are located in src/features/auth/.
Client component that displays a button to sign in. It automatically redirects to /auth/signin with the correct callbackUrl (the current page).
Props: VariantProps<typeof buttonVariants> (accepts button variants like size, variant, etc.)
import { SignInButton } from "@/features/auth/sign-in-button";
export default function Home() {
return (
<div>
<SignInButton size="lg" variant="default" />
</div>
);
}
Client component that displays the user's avatar with a dropdown menu. When the user clicks on it, they see a menu with actions (Dashboard, Account Settings, Admin, Theme, Logout).
Props:
{
user: {
name?: string | null;
email?: string | null;
image?: string | null;
}
}
import { LoggedInButton } from "@/features/auth/sign-in-button";
export default function Home() {
const user = await getUser();
if (!user) return null;
return (
<div>
<LoggedInButton user={user} />
</div>
);
}
Server component that automatically displays LoggedInButton or SignInButton based on user authentication status.
Props: None
Features:
Suspense with Skeleton fallbackimport { AuthButton } from "@/features/auth/auth-button";
export default function Header() {
return (
<div>
<AuthButton />
</div>
);
}
Client component with the same behavior as AuthButton. It automatically displays LoggedInButton or SignInButton based on the user session.
Props: None
Features:
useSession hook client-side"use client";
import { AuthButtonClient } from "@/features/auth/auth-button-client";
export default function ClientHeader() {
return (
<div>
<AuthButtonClient />
</div>
);
}
Logout is handled via the dropdown menu in LoggedInButton. The UserDropdownLogout component handles the logout action and automatically redirects to /auth/signin after logout.