lucia-auth
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "lucia-auth" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-1cfc006175d9ef271c46564835a416880de707e15aa26cf38a799268f0e37ccb. Verify the upstream source and version against https://github.com/TerminalSkills/skills before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
github.com
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Lucia authentication expert: help implement a lightweight session-based authentication layer in TypeScript, including email/password, OAuth (Google, GitHub, Discord), magic links, and two-factor authentication. Provides a simple, database-agnostic auth layer that is understandable and controllable without relying on complex full-featured auth platforms.
Introduction source: third_party · TerminalSkills · 1.0.0 Reference
SkillPi interpretation
- Testing
- Not tested
Browse files
Frontmatter
name: lucia-auth
description: >-
You are an expert in Lucia, the lightweight authentication library for
TypeScript. You help developers implement session-based authentication with
email/password, OAuth (Google, GitHub, Discord), magic links, and two-factor
authentication — providing a simple, database-agnostic auth layer that you
understand and control, without the complexity of full auth platforms.
license: Apache-2.0
compatibility: ''
metadata:
author: terminal-skills
version: 1.0.0
category: Backend Development
tags:
- authentication
- sessions
- oauth
- typescript
- auth
- securityLucia Auth — Simple Authentication
You are an expert in Lucia, the lightweight authentication library for TypeScript. You help developers implement session-based authentication with email/password, OAuth (Google, GitHub, Discord), magic links, and two-factor authentication — providing a simple, database-agnostic auth layer that you understand and control, without the complexity of full auth platforms.
Core Capabilities
Session Management
// lib/auth.ts
import { Lucia } from "lucia";
import { DrizzlePostgreSQLAdapter } from "@lucia-auth/adapter-drizzle";
import { db } from "./db";
import { users, sessions } from "./db/schema";
const adapter = new DrizzlePostgreSQLAdapter(db, sessions, users);
export const lucia = new Lucia(adapter, {
sessionCookie: {
expires: false, // Session cookie (cleared on browser close)
attributes: { secure: process.env.NODE_ENV === "production" },
},
getUserAttributes: (attributes) => ({
email: attributes.email,
name: attributes.name,
avatarUrl: attributes.avatar_url,
}),
});
// Email/password signup
async function signup(email: string, password: string, name: string) {
const hashedPassword = await new Argon2id().hash(password);
const userId = generateIdFromEntropySize(10);
await db.insert(users).values({
id: userId,
email,
name,
hashedPassword,
});
const session = await lucia.createSession(userId, {});
const sessionCookie = lucia.createSessionCookie(session.id);
return sessionCookie; // Set as response cookie
}
// Login
async function login(email: string, password: string) {
const user = await db.query.users.findFirst({ where: eq(users.email, email) });
if (!user) throw new Error("Invalid credentials");
const valid = await new Argon2id().verify(user.hashedPassword, password);
if (!valid) throw new Error("Invalid credentials");
const session = await lucia.createSession(user.id, {});
return lucia.createSessionCookie(session.id);
}
// Validate session (middleware)
async function validateRequest(request: Request) {
const cookieHeader = request.headers.get("Cookie");
const sessionId = lucia.readSessionCookie(cookieHeader ?? "");
if (!sessionId) return { user: null, session: null };
const result = await lucia.validateSession(sessionId);
return result; // { user, session } or { user: null, session: null }
}
// Logout
async function logout(sessionId: string) {
await lucia.invalidateSession(sessionId);
return lucia.createBlankSessionCookie();
}
OAuth (Google)
import { Google } from "arctic";
const google = new Google(
process.env.GOOGLE_CLIENT_ID!,
process.env.GOOGLE_CLIENT_SECRET!,
"https://myapp.com/auth/google/callback",
);
// Redirect to Google
app.get("/auth/google", async (c) => {
const [url, codeVerifier, state] = await google.createAuthorizationURL();
// Store codeVerifier and state in cookie
return c.redirect(url.toString());
});
// Handle callback
app.get("/auth/google/callback", async (c) => {
const { code, state } = c.req.query();
const tokens = await google.validateAuthorizationCode(code, codeVerifier);
const googleUser = await fetch("https://www.googleapis.com/oauth2/v3/userinfo", {
headers: { Authorization: `Bearer ${tokens.accessToken()}` },
}).then(r => r.json());
// Find or create user
let user = await db.query.users.findFirst({ where: eq(users.email, googleUser.email) });
if (!user) {
const userId = generateIdFromEntropySize(10);
[user] = await db.insert(users).values({
id: userId, email: googleUser.email, name: googleUser.name, avatar_url: googleUser.picture,
}).returning();
}
const session = await lucia.createSession(user.id, {});
const cookie = lucia.createSessionCookie(session.id);
return c.redirect("/dashboard", { headers: { "Set-Cookie": cookie.serialize() } });
});
Installation
npm install lucia arctic # Lucia + OAuth helpers
npm install @lucia-auth/adapter-drizzle # Or adapter-prisma, adapter-mongoose, etc.
npm install @node-rs/argon2 # Password hashing
Best Practices
- Session-based — Lucia uses server-side sessions + cookies; more secure than JWT for web apps
- Database-agnostic — Adapters for Drizzle, Prisma, Mongoose, better-sqlite3, Turso, etc.
- Arctic for OAuth — Use
arcticlibrary for OAuth providers; handles PKCE, state, tokens - Argon2 for passwords — Use
@node-rs/argon2for hashing; industry standard, timing-safe - Cookie security — Set
secure: truein production;httpOnlyis automatic - Session validation — Call
validateSession()on every request; auto-extends session expiry - Invalidation —
invalidateSessionfor logout;invalidateUserSessionsfor security reset - No magic — Lucia is explicit; you write the signup/login/oauth flows; you understand every line
Current listing version
1.0.0
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 解决Web开发中身份验证这一核心高频需求
- 覆盖完整的认证场景:会话管理、OAuth、密码哈希、2FA等
- 提供数据库无关的轻量级解决方案,避免复杂认证平台的臃肿
Highlights
- 触发词精准描述Lucia专家身份和核心能力
- 明确覆盖email/password、OAuth、magic links、2FA等变体场景
- 边界清晰,不会与其他认证工具混淆
Areas to improve
-
缺少When to Use章节 Reported severity: Minor
文档结构完整但缺少明确的When to Use使用场景说明章节
Recommendation: 建议添加When to Use章节,明确说明何时使用此Skill
Highlights
- Phase/步骤清晰,有Core Capabilities、Installation、Best Practices等完整结构
- 包含端到端的代码示例,涵盖会话管理、OAuth等核心功能
- frontmatter完整,包含name、description、license、metadata等信息
Highlights
- 工具来源明确:lucia、arctic、@node-rs/argon2等均为官方推荐库
- 参数使用正确,包含安全最佳实践(secure cookie、httpOnly等)
- 覆盖主要异常处理场景,如无效凭证、会话验证等
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
-
Install or fetch external dependencies
Use official sources and pin versions. Check install scripts in an isolated environment. This document check does not cover code downloaded later.
Mentioned in main document · lines 143, 144, 145 -
Accounts, secrets or authorization
Use a dedicated least-privilege account. Keep secrets out of public content and command logs; verify the receiving service and tenant.
Mentioned in main document · lines 6, 18, 26, 73, 76
Domains or addresses referenced in the document
These addresses may be documentation links or examples, not an approved network allowlist. Verify actual destinations and outgoing data before use.
- myapp.com
- www.googleapis.com
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.