Update your Mongoose client to Lucia v2

Install the latest version of the Mongoose adapter.

npm i @lucia-auth/adapter-mongoose@latest
pnpm add @lucia-auth/adapter-mongoose@latest
yarn add @lucia-auth/adapter-mongoose@latest

Remove single use keys#

// db.<collection_name>
	expires: { $ne: null }

Update Key model#

Remove expires and primary_key fields.

const Key = mongoose.model(
	new mongoose.Schema(
			_id: {
				type: String
			user_id: {
				type: String,
				required: true
			hashed_password: String
		{ _id: false }

Initialize adapter#

mongoose() is now a named export instead of a default export. The adapter now takes models for users, keys, and session, instead of the Mongoose client.

import { lucia } from "lucia";
import { mongoose } from "@lucia-auth/adapter-mongoose";
import mongodb from "mongoose";

const User = mongoose.model();
const Key = mongoose.model();
const Session = mongoose.model();

const auth = lucia({
	adapter: mongoose({
	// ...

// handle connection
mongodb.connect(mongoUri, options);