DEV Community

Alex Spinov
Alex Spinov

Posted on

Lucia Auth Has a Free Authentication Library That Gives You Full Control

Lucia is an auth library for your server. Unlike hosted auth services, you own the code, the sessions, and the database schema.

What You Get for Free

  • Session management — secure cookie-based sessions
  • Database agnostic — any SQL or NoSQL database
  • OAuth helpers — GitHub, Google, Discord, etc.
  • Password hashing — Argon2id
  • Full control — you own the code
  • Framework agnostic — Next.js, SvelteKit, Astro, Express

Session Management

import { Lucia } from 'lucia';
import { DrizzleSQLiteAdapter } from '@lucia-auth/adapter-drizzle';

const lucia = new Lucia(new DrizzleSQLiteAdapter(db, sessionTable, userTable));

// Create session
const session = await lucia.createSession(userId, {});
const cookie = lucia.createSessionCookie(session.id);

// Validate session
const { session, user } = await lucia.validateSession(sessionId);
Enter fullscreen mode Exit fullscreen mode

Lucia vs NextAuth

Feature Lucia NextAuth
Control Full Opinionated
Database Any Adapters
Sessions Cookie-based JWT or DB
Learning curve Higher Lower

Need auth help? GitHub or spinov001@gmail.com

Top comments (0)