Authentication Features

Implement and customize authentication flows including sign in, sign up, password reset, and MFA.

The kit provides complete authentication flows out of the box, built on Better Auth:

  • ✅ Email/Password Sign In
  • ✅ Email/Password Sign Up
  • ✅ Magic Link Sign In
  • ✅ Password Reset
  • ✅ Multi-Factor Authentication (MFA)
  • ✅ Email Verification
  • ✅ Session Management

Authentication Topics

In this section, we'll learn how to use the authentication features of the kit:

  1. Sign In - Sign in with email/password or magic link
  2. Sign Up - Create new user accounts
  3. Password Reset - Reset forgotten passwords
  4. Session Handling - Protect routes and check auth

Accessing Auth Pages

  • Sign In: /auth/sign-in
  • Sign Up: /auth/sign-up
  • Password Reset Request: /auth/reset-password
  • Password Reset: /reset-password
  • Verify Email: /auth/verify (when email verification is enabled)

Getting Current User

Retrieve the current user session in Server contexts (API routes, server actions, server components) using getSession:

import { getSession } from '@kit/better-auth/context';
const session = await getSession();
if (session) {
console.log(session.user.id);
console.log(session.user.email);
console.log(session.user.name);
}

This is the best way to protect pages for authed users:

import { redirect } from 'next/navigation';
import { getSession } from '@kit/better-auth/context';
async function ProtectedPage() {
const session = await getSession();
if (!session) {
redirect('/auth/sign-in');
}
// you can now show content to the user based on their authorization
}

Next: Sign In →