npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@aizvi/auth-sqlite

v2.0.1

Published

SQLite storage adapter for @aizvi/auth. sqliteAdapter() auto-picks bun:sqlite under Bun and better-sqlite3 under Node.js; createSqliteAuthAdapter() also works with any driver you already have open, including Node's built-in node:sqlite.

Readme

@aizvi/auth-sqlite

A SQLite storage adapter for @aizvi/auth. Point it at a .sqlite file, or a database connection you already have, and your auth system has somewhere to store users and sessions. No separate database server needed.

It creates its own users and mobile_auth_sessions tables the first time it runs, and never touches anything else in your database.

Install

npm install @aizvi/auth @aizvi/auth-sqlite
pnpm add @aizvi/auth @aizvi/auth-sqlite
yarn add @aizvi/auth @aizvi/auth-sqlite
bun add @aizvi/auth @aizvi/auth-sqlite

Quick start

The easiest way to use this package: give it a file path, and it opens (or creates) the database for you.

import { createAuthRouter } from '@aizvi/auth';
import { sqliteAdapter } from '@aizvi/auth-sqlite';

app.use(
  '/auth',
  createAuthRouter({
    adapter: sqliteAdapter({ file: './data.sqlite' }),
    mailer: myEmailSender,
    jwtSecret: process.env.JWT_SECRET!,
  })
);

The file, and any missing parent directories, is created automatically if it doesn't already exist, with journal_mode = WAL and foreign_keys = ON set for you.

Which driver does this use?

sqliteAdapter() picks the right driver automatically based on where your code is running, so you never have to think about it:

Same function, same behavior, either way. Nothing in your code needs to change if you switch runtimes.

Already have a SQLite connection? Use that instead

If your app already opens its own SQLite connection, for example with Node's built in node:sqlite, or a better-sqlite3 instance configured with your own options, you don't need sqliteAdapter() to open a second one. Hand your existing connection straight to createSqliteAuthAdapter() instead:

import { DatabaseSync } from 'node:sqlite';
import { createAuthRouter } from '@aizvi/auth';
import { createSqliteAuthAdapter } from '@aizvi/auth-sqlite';

const db = new DatabaseSync('./data.sqlite'); // the connection your app already uses
db.exec('PRAGMA journal_mode = WAL');
db.exec('PRAGMA foreign_keys = ON');

app.use(
  '/auth',
  createAuthRouter({
    adapter: createSqliteAuthAdapter(db),
    mailer: myEmailSender,
    jwtSecret: process.env.JWT_SECRET!,
  })
);

This works with any driver that can exec() SQL, prepare() a statement, and run() or get() it, which covers node:sqlite, better-sqlite3, and bun:sqlite. That way you only ever have one open connection to your database, shared between your auth tables and everything else your app stores.

If you're adding auth to an app that already has its own users table with the same columns this package expects (see Schema below), createSqliteAuthAdapter() simply uses it as is. It only creates the tables if they don't already exist.

More examples

Using better-sqlite3 with your own options, instead of the defaults sqliteAdapter() picks:

import Database from 'better-sqlite3';
import { createSqliteAuthAdapter } from '@aizvi/auth-sqlite';

const db = new Database('./data.sqlite', { timeout: 5000, readonly: false });
db.pragma('journal_mode = WAL');

const adapter = createSqliteAuthAdapter(db);

Sharing one connection between auth and the rest of your app:

import { DatabaseSync } from 'node:sqlite';
import { createSqliteAuthAdapter } from '@aizvi/auth-sqlite';

// Your app's single, shared database connection, used everywhere.
export const db = new DatabaseSync('./data.sqlite');
db.exec('PRAGMA journal_mode = WAL');
db.exec('PRAGMA foreign_keys = ON');

// Your own tables, created however you already do it.
db.exec('CREATE TABLE IF NOT EXISTS posts (id TEXT PRIMARY KEY, title TEXT NOT NULL)');

// The auth adapter reuses the exact same connection and file.
export const authAdapter = createSqliteAuthAdapter(db);

Running the migration yourself, ahead of time:

import { DatabaseSync } from 'node:sqlite';
import { migrate, createSqliteAuthAdapter } from '@aizvi/auth-sqlite';

const db = new DatabaseSync('./data.sqlite');
migrate(db); // creates users / mobile_auth_sessions if they don't exist yet

// ...later, once you're ready to build the router:
const adapter = createSqliteAuthAdapter(db);

Schema

On first use, this creates:

CREATE TABLE IF NOT EXISTS users (
  id TEXT PRIMARY KEY,
  email TEXT UNIQUE NOT NULL,
  password_hash TEXT NOT NULL,
  is_verified INTEGER NOT NULL DEFAULT 0,
  verification_code TEXT,
  verification_expires TEXT,
  reset_code TEXT,
  reset_expires TEXT,
  created_at TEXT NOT NULL,
  updated_at TEXT NOT NULL
);

CREATE TABLE IF NOT EXISTS mobile_auth_sessions (
  id TEXT PRIMARY KEY,
  user_id TEXT NOT NULL REFERENCES users(id),
  refresh_token_hash TEXT NOT NULL,
  expires_at TEXT NOT NULL,
  revoked_at TEXT,
  created_at TEXT NOT NULL,
  updated_at TEXT NOT NULL
);

Only the SHA-256 hash of a refresh token is ever stored, never the raw token itself.

API

sqliteAdapter(options)

| Option | Required | Description | | ------ | -------- | ----------- | | file | yes | Path to the SQLite file. Created automatically, including parent directories, if it doesn't exist. |

Returns an adapter ready to pass to createAuthRouter. Also has a .close() method if you need to close the connection manually. Most apps never need to call this.

createSqliteAuthAdapter(db)

Takes an already open database connection (anything implementing exec, prepare().run()/.get(), and close(); see src/driver.ts for the exact minimal interface) and returns the same kind of adapter.

migrate(db)

Runs the table creation step on its own, if you want to control exactly when it happens rather than letting sqliteAdapter/createSqliteAuthAdapter run it for you automatically.

Code of Conduct

See CODE_OF_CONDUCT.md.

License

MIT (see license.txt)