Step-by-Step Tutorial
Everything you need to replicate this professional auth system.
01Project Setup
Initialize Next.js with pnpm and install core dependencies for Auth and Database.
Ready to copy
pnpm create next-app@latest my-app cd my-app pnpm add better-auth drizzle-orm @libsql/client pnpm add -D drizzle-kit dotenv
02Database Configuration
Setup Turso SQLite and define your Drizzle schema for Better Auth tables.
Ready to copy
// db/schema.ts
import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
export const user = sqliteTable("user", {
id: text("id").primaryKey(),
name: text("name").notNull(),
email: text("email").notNull().unique(),
// ... other tables: session, account03Auth Server Logic
Configure Better Auth with the Drizzle adapter and Google social provider.
Ready to copy
// lib/auth.ts
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "sqlite",
schema: schema,
}),
socialProviders: {
google: { clientId: ..., clientSecret: ... }
}
})04Client-Side Login Button
The classic login button that triggers the Google OAuth flow.
Ready to copy
"use client";
import { authClient } from "@/lib/auth-client";
export function LoginButton() {
return (
<button onClick={() => authClient.signIn.social({ provider: "google" })}>
Login with Google
</button>
);
}05Route Protection
Secure your pages using Next.js Middleware to verify sessions before access.
Ready to copy
// middleware.ts
export default async function middleware(req) {
const { data: session } = await betterFetch("/api/auth/get-session");
if (!session) return NextResponse.redirect("/");
}Want the full source?
Check out the complete GUIDE.md in the project root for more details on Turso CLI and Google Cloud Console configuration.