Lucia: Authentication Implementation Guide

repository·main·Indexed Apr 15, 2026

https://github.com/lucia-auth/lucia

Lucia is an open-source educational resource for implementing authentication and session management from scratch in JavaScript and TypeScript. It provides code examples and guides to build custom session handling tailored to specific databases, frameworks, and runtimes. Note: Lucia v3 is deprecated as of March 2025. The project focuses on broad compatibility and flexibility rather than a monolithic library. Includes implementation notes for Next.js and SvelteKit, token bucket rate limiting, and secure session cookie configuration.

Tokens
29.5K
Snippets
71
Records
111
Agent score
95%

What's inside lucia-auth/lucia

  1. Tutorial: Google OAuth in Astro

    main
    This guide walks through implementing Google OAuth in an Astro project using Lucia for session management and Arctic for OAuth handling.
  2. Initialize Google Provider with Arctic

    main

    Install the arctic package and initialize the Google provider with your credentials and redirect URI.

    Installation:

    npm install arctic

    Initialization Code (lib/auth.ts or similar):

    import { Google } from "arctic";
    
    export const google = new Google(
    	process.env.GOOGLE_CLIENT_ID,
    	process.env.GOOGLE_CLIENT_SECRET,
    	"http://localhost:3000/login/google/callback"
    );

    This google instance is used to generate authorization URLs and validate authorization codes.

    Sources: pages/tutorials/google-oauth/nextjs.md

  3. 3. Setup Arctic

    main

    Install the Arctic library:

    npm install arctic

    Initialize the Google provider in your server code (e.g., $lib/server/oauth.ts):

    import { Google } from "arctic";
    import { GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET } from "$env/static/private";
    
    export const google = new Google(
    	GOOGLE_CLIENT_ID,
    	GOOGLE_CLIENT_SECRET,
    	"http://localhost:5173/login/google/callback"
    );
  4. 3. Setup Arctic

    main

    Install the Arctic OAuth library:

    npm install arctic

    Initialize the GitHub provider in your code (e.g., lib/oauth.ts):

    import { GitHub } from "arctic";
    
    export const github = new GitHub(
    	process.env.GITHUB_CLIENT_ID,
    	process.env.GITHUB_CLIENT_SECRET,
    	null
    );
  5. 3. Setup Arctic

    main

    Install the Arctic OAuth library:

    npm install arctic

    Initialize the GitHub provider in your server code (e.g., $lib/server/oauth.ts):

    import { GitHub } from "arctic";
    import { GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET } from "$env/static/private";
    
    export const github = new GitHub(GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET, null);