
Lucia Auth Deprecated in 2025? Switch to Better Auth! Modern authentication for frameworks, plugins & multi-method setups.
As of 2025, Lucia-auth, a popular authentication library, is reaching the end of its support lifecycle. With that change, developers are seeking alternatives that provide robust, flexible, and easy-to-use authentication solutions. Enter Better Auth—a new, comprehensive, and framework-agnostic authentication (and authorization) library for TypeScript.
Better Auth brings powerful features, a growing plugin ecosystem, and the ability to handle complex authentication scenarios like 2FA and multi-tenant support. Though still in beta, it is already proving to be an excellent option for developers looking to future-proof their TypeScript applications.
In this article, we’ll guide you through setting up Better Auth in your Next.js project using Drizzle ORM and PostgreSQL.
Before you begin, ensure you have the following in place:
Let’s start by adding Better Auth to your Next.js project:
pnpm install better-auth.env file in the root of your project and add the following environment variables:BETTER_AUTH_SECRET=<Your generated secret key>BETTER_AUTH_URL=http://localhost:3000BETTER_AUTH_TRUSTED_ORIGINS="http://localhost:3000,https://example.com"Create a file named auth.ts in root of your application
import { betterAuth } from "better-auth";
export const auth = betterAuth({
// Add your configuration here
})Better Auth requires a database to store user data. By default, it uses Kysely for database queries, which supports PostgreSQL, MySQL, and SQLite.
Since we are using PostgreSQL with the Drizzle ORM adapter, the configuration would look like this:
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { db } from "@/db"; // your drizzle instance
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "pg",
})
});For performance optimization, the built-in Kysely adapter is recommended when supported. However, Drizzle works well for custom setups.
Better Auth provides a CLI tool to help generate the required database schema. Run the following command to generate an ORM schema or SQL migration file:
npx @better-auth/cli generateNext, run the migration command to create the necessary tables in your PostgreSQL database:
npx @better-auth/cli migrateIf you need to manually create the schema, refer to the Better Auth documentation.
Better Auth supports several authentication methods out of the box. Here’s an example of how to configure email/password authentication along with GitHub as a social sign-on provider:
import { betterAuth } from "better-auth"
import { github } from "better-auth/social-providers"
export const auth = betterAuth({
emailAndPassword: {
enabled: true
},
socialProviders: {
github: {
clientId: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET,
}
}
});Better Auth also supports additional methods such as passkeys, magic links, and more, which can be added through its plugin ecosystem.
To handle authentication requests, create a new API route for /api/auth/*. In Next.js, you would typically create a catch-all route handler as follows:
Create a new file under app/api/auth/[...all]/route.ts:
import { auth } from "@/lib/auth";
import { toNextJsHandler } from "better-auth/next-js";
export const { POST, GET } = toNextJsHandler(auth);This file will manage all incoming authentication-related requests.
On the client side, Better Auth provides helper functions to interact with the authentication server. Here’s how to set it up:
Create a lib/auth-client.ts file and add the following:
import { createAuthClient } from "better-auth/react";
export const authClient = createAuthClient({
baseURL: "http://localhost:3000", // Your auth server base URL
});You can also export specific methods from authClient as needed:
export const { signIn, signUp, useSession } = authClient();That’s it! You now have a fully functional Better Auth setup in your Next.js project, using Drizzle ORM and PostgreSQL for database management. With Better Auth’s framework-agnostic approach and plugin-friendly architecture, it provides a modern solution for all your authentication needs.
If you’re looking to extend functionality, be sure to explore Better Auth’s comprehensive set of plugins for advanced use cases like 2FA, magic links, and more.
For more information and detailed guides, visit the official Better Auth documentation.