Authentication
Set up authentication for your LaunchNext project.
Overview
LaunchNext uses better-auth for handling authentication. It provides a simple, secure, and flexible authentication solution for Next.js applications.
Supported Providers
- Email + Password — Traditional authentication with hashed passwords
- Magic Link — Passwordless authentication via email
- Google OAuth — Sign in with Google
- GitHub OAuth — Sign in with GitHub
Setup
1. Install Dependencies
pnpm add better-auth2. Configure Environment Variables
Add the required environment variables to your .env.local:
AUTH_SECRET=generate-a-random-secret
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret3. Create API Route
Create the catch-all API route at src/app/api/auth/[...all]/route.ts:
import { auth } from "@/lib/auth";
export const { GET, POST } = auth.handlers;Protected Routes
Use middleware or server-side checks to protect routes:
import { auth } from "@/lib/auth";
export default async function DashboardPage() {
const session = await auth();
if (!session) redirect("/signin");
// ...
}