Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

lucia

pilcrowOnPaper172.6kMIT3.2.2TypeScript support: included

A simple and flexible authentication library

lucia, lucia-auth, authentication, auth

readme

lucia

An open source auth library that abstracts away the complexity of handling sessions. It works alongside your database to provide an API that's easy to use, understand, and extend.

Documentation

Changelog

Installation

npm install lucia
pnpm add lucia
yarn add lucia

changelog

lucia

3.2.2

Patch changes

  • Fix cookie expiration.

3.2.1

Patch changes

3.2.0

Minor changes

Patch changes

3.1.1

  • Fix types.

3.1.0

  • Add option to configure user ID type (#1472).

3.0.1

  • Fix LegacyScrypt generating malformed hash (see #1370 - no security concerns)

3.0.0

See the migration guide.

2.7.6

Patch changes

2.7.5

Patch changes

  • #1301 by @matteopolak : Update SvelteKit middleware to be compatible with SvelteKit v2

2.7.4

Patch changes

2.7.3

Patch changes

2.7.2

Patch changes

2.7.1

Patch changes

2.7.0

Minor changes

Patch changes

2.6.0

Minor changes

Patch changes

  • #1105 by @pilcrowOnPaper : Fix Auth.useKey() accepting any password if the key password was set to null

  • #1105 by @pilcrowOnPaper : Fix Auth.createUser() setting key password to null if key.password was an empty string

2.5.0

Minor changes

Patch changes

  • #1079 by @pilcrowOnPaper : Fix Auth.handleRequest() causing error in middleware when nextjs() was used

2.4.2

Patch changes

  • #1046 by @pilcrowOnPaper : Fix AuthRequest.validateBearerToken() returning null when session is idle

2.4.1

Patch changes

2.4.0

Minor changes

  • #986 by @KazuumiN : Fixed updateKeyPassword() to return a Promise<Key>

Patch changes

2.3.0

Minor changes

2.2.0

Minor changes

2.1.0

Minor changes

2.0.0

Major changes

2.0.0-beta.7

Major changes

Minor changes

  • #864 by @pilcrowOnPaper : Export generateLuciaPasswordHash, validateLuciaPasswordHash from /utils

Patch changes

2.0.0-beta.6

Major changes

  • #836 by @pilcrowOnPaper : User ids and session ids only consist of lowercase letters and numbers by default

  • #839 by @pilcrowOnPaper : AuthRequest.validate() and Auth.validateBearerToken() throws database errors

Minor changes

2.0.0-beta.5

Major changes

Patch changes

  • #815 by @pilcrowOnPaper : Fix getSessionAndUser() adapter method getting called when using session adapters

2.0.0-beta.4

Patch changes

2.0.0-beta.3

Major changes

2.0.0-beta.2

Major changes

  • #739 by @pilcrowOnPaper : Auth.readSessionCookie() and Auth.readBearerToken() takes the session and authorization header value respectively

  • #754 by @pilcrowOnPaper : Auth.validateRequestOrigin() checks for CSRF regardless of csrfProtection config

  • #753 by @pilcrowOnPaper : Rename requestOrigins config to allowedRequestOrigins

Minor changes

2.0.0-beta.1

Patch changes

2.0.0-beta.0

Major changes

  • #682 by @pilcrowOnPaper : Update configuration

    • Remove autoDatabaseCleanup

    • Remove transformDatabaseUser() (see transformUserAttributes())

    • Replace generateCustomUserId() with generateUserId()

    • Replace hash with passwordHash

    • Replace origin with requestOrigins

    • Replace sessionCookie with sessionCookie.attributes

    • Add sessionCookie.name for setting session cookie name

    • Add transformUserAttributes() for defining user attributes (userId is automatically included)

    • Add transformSessionAttributes() for defining session attributes

  • #682 by @pilcrowOnPaper : Update Auth methods:

    • Remove getSessionUser()

    • Remove validateSessionUser()

    • Remove parseRequestHeaders()

    • Add readSessionCookie()

    • Add validateRequestOrigin()

  • #682 by @pilcrowOnPaper : Remove primary keys

    • Remove Key.primary

    • Rename Auth.createUser() params options.primaryKey to options.key

    • Remove column key(primary_key)

  • #682 by @pilcrowOnPaper : Remove single use keys

    • Lucia v2 no longer supports @lucia-auth/tokens

    • Remove Session.type

    • Update Auth.createKey() params

    • Remove column key(expires)

  • #682 by @pilcrowOnPaper : Update Session

    • Remove Session.userId

    • Add Session.user

  • #682 by @pilcrowOnPaper : Remove AuthRequest.validateUser()

  • #682 by @pilcrowOnPaper : Introduce custom session attributes

    • Update Auth.createSession() params

    • Update behavior of Auth.renewSession() to include attributes of old session to renewed session automatically

  • #682 by @pilcrowOnPaper : Overhaul adapter API

    • Remove UserAdapter.updateUserAttributes()

    • Remove UserAdapter.deleteNonPrimaryKey()

    • Remove UserAdapter.updateKeyPassword()

    • Remove Adapter?.getSessionAndUserBySessionId()

    • Update UserAdapter.setUser() params

    • Remove UserAdapter.getKey() params shouldDataBeDeleted()

    • Add UserAdapter.updateUser()

    • Add UserAdapter.deleteKey()

    • Add UserAdapter.updateKey()

    • Add SessionAdapter.updateSession()

    • Add Adapter.getSessionAndUser()

    • Rename type AdapterFunction to InitializeAdapter

  • #682 by @pilcrowOnPaper : Update adapter specifications

    • Insert and update methods do not return anything

    • Insert and update methods for sessions and keys may optionally throw a Lucia error on invalid user id

    • Insert methods do not throw Lucia errors on duplicate session and user ids

  • #682 by @pilcrowOnPaper : Remove errors:

    • AUTH_DUPLICATE_SESSION_ID

    • AUTO_USER_ID_GENERATION_NOT_SUPPORTED

    • AUTH_EXPIRED_KEY

  • #682 by @pilcrowOnPaper : Remove auto database clean up functionality

  • #682 by @pilcrowOnPaper : Update Middleware takes a new Context params

  • #682 by @pilcrowOnPaper : Update exports:

    • Replace default export with named lucia()

    • Removed generateRandomString()

    • Removed serializeCookie()

    • Removed Cookie

  • #682 by @pilcrowOnPaper : Rename SESSION_COOKIE_NAME to DEFAULT_SESSION_COOKIE_NAME

  • #682 by @pilcrowOnPaper : NPM package lucia-auth is renamed to lucia

  • #682 by @pilcrowOnPaper : Update RequestContext:

    • Add RequestContext.headers.authorization

    • Add optional RequestContext.storedSessionCookie

Minor changes

  • #682 by @pilcrowOnPaper : Support bearer tokens

    • Add Auth.readBearerToken()

    • Add AuthRequest.validateBearerToken()

  • #682 by @pilcrowOnPaper : New lucia/utils export:

    • generateRandomString()

    • serializeCookie()

    • isWithinExpiration()