{"_id":"@aizvi/auth-sqlite","_rev":"4-f80fba3590f0752b3a495e3065f72c3b","name":"@aizvi/auth-sqlite","dist-tags":{"latest":"2.0.1"},"versions":{"1.0.0":{"name":"@aizvi/auth-sqlite","version":"1.0.0","license":"MIT","_id":"@aizvi/auth-sqlite@1.0.0","maintainers":[{"name":"ahmadhuss","email":"ahmadhussnain787@gmail.com"}],"dist":{"shasum":"a5faef61b723dd57834624b35c397307d7014ab8","tarball":"https://registry.npmjs.org/@aizvi/auth-sqlite/-/auth-sqlite-1.0.0.tgz","fileCount":19,"integrity":"sha512-P9z+F9++vEGgJBSOGACmbt00VzTOSEaLT31xSEbsSNVa3gj9a7KlxEC5ZcfkLao7rdyoj/22MnpOvB+dnqke5w==","signatures":[{"sig":"MEYCIQDcTbuEG4rU8W7IC214I4/+G2Fidd4U8yqjFDx/SkKwjgIhAKDmO9nVPaVPGkPaVi/B1Q0dB0Qf8uIXzTJIOaptSTsc","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":227879},"main":"./dist/index.cjs","type":"commonjs","types":"./dist/index.d.ts","module":"./dist/index.mjs","exports":{".":{"bun":{"types":"./dist/index.bun.d.ts","import":"./dist/index.bun.mjs","require":"./dist/index.bun.cjs"},"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.cjs"}},"gitHead":"046b002c0fa5682733aff437882d8465958b5158","scripts":{"dev":"tsup --watch","test":"bun run test:bun && bun run test:node","build":"tsup","test:bun":"bun test test/adapter.bun.test.ts","test:node":"tsx --test \"test/adapter.node.test.ts\"","typecheck":"tsc --noEmit"},"_npmUser":{"name":"ahmadhuss","email":"ahmadhussnain787@gmail.com"},"_npmVersion":"11.12.1","description":"SQLite storage adapter for @aizvi/auth. Uses bun:sqlite under Bun and better-sqlite3 under Node.js, chosen automatically.","directories":{},"_nodeVersion":"24.15.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.23.1","tsup":"^8.3.0","typescript":"^5.6.3","@aizvi/auth":"workspace:*","@types/better-sqlite3":"^7.6.11"},"peerDependencies":{"@aizvi/auth":"^1.0.0"},"optionalDependencies":{"better-sqlite3":"^11.5.0"},"_npmOperationalInternal":{"tmp":"tmp/auth-sqlite_1.0.0_1784753162933_0.00865345677370244","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@aizvi/auth-sqlite","version":"1.0.1","keywords":["auth","authentication","sqlite","better-sqlite3","bun-sqlite","database-adapter","storage-adapter","bun","typescript"],"license":"MIT","_id":"@aizvi/auth-sqlite@1.0.1","maintainers":[{"name":"ahmadhuss","email":"ahmadhussnain787@gmail.com"}],"homepage":"https://github.com/Aizvi/auth/tree/main/packages/sqlite#readme","bugs":{"url":"https://github.com/Aizvi/auth/issues"},"dist":{"shasum":"563a649f39d46262934d075b1ca9606ac848b67c","tarball":"https://registry.npmjs.org/@aizvi/auth-sqlite/-/auth-sqlite-1.0.1.tgz","fileCount":19,"integrity":"sha512-zSwpVV6fogaRPREGWfsZhRqtE4ao2d1lHjfWV9wHxz4kjNyrDjL+NJ2QAUgQhXe9B9Jxdeh7T3ZmIUXntFRrtQ==","signatures":[{"sig":"MEYCIQD5n9qEYYgnQok71UIaoTYK4KmO0K0rbsAaryxzV6Tg3QIhAPPMtX+o6EPwv3v72tlqLNSjp4IW5c0eMjW625NdOghz","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":227018},"main":"./dist/index.cjs","type":"commonjs","types":"./dist/index.d.ts","module":"./dist/index.mjs","exports":{".":{"bun":{"types":"./dist/index.bun.d.ts","import":"./dist/index.bun.mjs","require":"./dist/index.bun.cjs"},"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.cjs"}},"gitHead":"be127805c7e77909f28451353d7eebbf9cb9376e","scripts":{"dev":"tsup --watch","test":"bun run test:bun && bun run test:node","build":"tsup","test:bun":"bun test test/adapter.bun.test.ts","test:node":"tsx --test \"test/adapter.node.test.ts\"","typecheck":"tsc --noEmit"},"_npmUser":{"name":"ahmadhuss","email":"ahmadhussnain787@gmail.com"},"repository":{"url":"git+https://github.com/Aizvi/auth.git","type":"git","directory":"packages/sqlite"},"_npmVersion":"10.9.8","description":"SQLite storage adapter for @aizvi/auth. Uses bun:sqlite under Bun and better-sqlite3 under Node.js, chosen automatically.","directories":{},"_nodeVersion":"22.23.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.23.1","tsup":"^8.3.0","typescript":"^5.6.3","@aizvi/auth":"workspace:*","@types/better-sqlite3":"^7.6.11"},"peerDependencies":{"@aizvi/auth":"^1.0.1"},"optionalDependencies":{"better-sqlite3":"^11.5.0"},"_npmOperationalInternal":{"tmp":"tmp/auth-sqlite_1.0.1_1784755246965_0.24376499312204758","host":"s3://npm-registry-packages-npm-production"}},"2.0.0":{"name":"@aizvi/auth-sqlite","version":"2.0.0","keywords":["auth","authentication","sqlite","better-sqlite3","bun-sqlite","database-adapter","storage-adapter","bun","typescript"],"license":"MIT","_id":"@aizvi/auth-sqlite@2.0.0","maintainers":[{"name":"ahmadhuss","email":"ahmadhussnain787@gmail.com"}],"homepage":"https://github.com/Aizvi/auth/tree/main/packages/sqlite#readme","bugs":{"url":"https://github.com/Aizvi/auth/issues"},"dist":{"shasum":"1f9b348f9ceecac16a3a930183278acc7dd31ebb","tarball":"https://registry.npmjs.org/@aizvi/auth-sqlite/-/auth-sqlite-2.0.0.tgz","fileCount":19,"integrity":"sha512-ShorLIRrF1pUUZwvDIyqh1AXYb+QliMMxxXwDXOpAFlfuAzuvqas9xqRoAoII56Tp0+Ezp0J7p6hNDSeOL0RHA==","signatures":[{"sig":"MEUCIQDzkB4hpeExAS++mchGTSeJ9J9Bd6hVARzGWJFiE3ZgywIgFjg7YflrhZvVVdFJDKMDvkyIxDw0iMVqly/iG5HjRvA=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":228896},"main":"./dist/index.cjs","type":"commonjs","types":"./dist/index.d.ts","module":"./dist/index.mjs","exports":{".":{"bun":{"types":"./dist/index.bun.d.ts","import":"./dist/index.bun.mjs","require":"./dist/index.bun.cjs"},"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.cjs"}},"gitHead":"39abe7f9feb78133ec468222ba14ddc5115fda5c","scripts":{"dev":"tsup --watch","test":"bun run test:bun && bun run test:node","build":"tsup","test:bun":"bun test test/adapter.bun.test.ts","test:node":"tsx --test \"test/adapter.node.test.ts\" \"test/adapter.node-sqlite.test.ts\"","typecheck":"tsc --noEmit"},"_npmUser":{"name":"ahmadhuss","email":"ahmadhussnain787@gmail.com"},"repository":{"url":"git+https://github.com/Aizvi/auth.git","type":"git","directory":"packages/sqlite"},"_npmVersion":"10.9.8","description":"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.","directories":{},"_nodeVersion":"22.23.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.23.1","tsup":"^8.3.0","typescript":"^5.6.3","@aizvi/auth":"workspace:*","@types/better-sqlite3":"^7.6.11"},"peerDependencies":{"@aizvi/auth":"^1.1.0"},"optionalDependencies":{"better-sqlite3":"^11.5.0"},"_npmOperationalInternal":{"tmp":"tmp/auth-sqlite_2.0.0_1784949102471_0.5928864835608789","host":"s3://npm-registry-packages-npm-production"}},"2.0.1":{"name":"@aizvi/auth-sqlite","version":"2.0.1","description":"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.","keywords":["auth","authentication","sqlite","better-sqlite3","bun-sqlite","database-adapter","storage-adapter","bun","typescript"],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/Aizvi/auth.git","directory":"packages/sqlite"},"homepage":"https://github.com/Aizvi/auth/tree/main/packages/sqlite#readme","bugs":{"url":"https://github.com/Aizvi/auth/issues"},"type":"commonjs","main":"./dist/index.cjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"bun":{"types":"./dist/index.bun.d.ts","import":"./dist/index.bun.mjs","require":"./dist/index.bun.cjs"},"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.cjs"}},"publishConfig":{"access":"public"},"scripts":{"build":"tsup","dev":"tsup --watch","test":"bun run test:bun && bun run test:node","test:bun":"bun test test/adapter.bun.test.ts","test:node":"tsx --test \"test/adapter.node.test.ts\" \"test/adapter.node-sqlite.test.ts\"","typecheck":"tsc --noEmit"},"peerDependencies":{"@aizvi/auth":"^1.1.2"},"optionalDependencies":{"better-sqlite3":"^11.5.0"},"devDependencies":{"@aizvi/auth":"workspace:*","@types/better-sqlite3":"^7.6.11","tsup":"^8.3.0","tsx":"^4.23.1","typescript":"^5.6.3"},"_id":"@aizvi/auth-sqlite@2.0.1","gitHead":"6bde1f9a6540c844ec31eb4b0f99afd31e2568bb","_nodeVersion":"22.23.1","_npmVersion":"10.9.8","dist":{"integrity":"sha512-23zuRkjy8azYq/+SN90ue91f2bBDPPUmQmCg3G/u4vrIJA1+hF7FvgHGyPz3e+HAxO0jnD6lmYYx3+j83H+Arw==","shasum":"7a2e430edfd8abbbe5d928cd6d9f62720a2bcc07","tarball":"https://registry.npmjs.org/@aizvi/auth-sqlite/-/auth-sqlite-2.0.1.tgz","fileCount":19,"unpackedSize":233921,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIBLtOLrQQgTOKxLgSbDL+VEUnhD+zkGdRvyRtppw0QcPAiEA/ZYZ761iIUdAKG9XQYuLpwn7H4WVCOwleu/5aDejiDU="}]},"_npmUser":{"name":"ahmadhuss","email":"ahmadhussnain787@gmail.com"},"directories":{},"maintainers":[{"name":"ahmadhuss","email":"ahmadhussnain787@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/auth-sqlite_2.0.1_1784953881252_0.28604125172214734"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-22T20:46:02.772Z","modified":"2026-07-25T04:31:21.643Z","1.0.0":"2026-07-22T20:46:03.137Z","1.0.1":"2026-07-22T21:20:47.167Z","2.0.0":"2026-07-25T03:11:42.667Z","2.0.1":"2026-07-25T04:31:21.464Z"},"bugs":{"url":"https://github.com/Aizvi/auth/issues"},"license":"MIT","homepage":"https://github.com/Aizvi/auth/tree/main/packages/sqlite#readme","keywords":["auth","authentication","sqlite","better-sqlite3","bun-sqlite","database-adapter","storage-adapter","bun","typescript"],"repository":{"type":"git","url":"git+https://github.com/Aizvi/auth.git","directory":"packages/sqlite"},"description":"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.","maintainers":[{"name":"ahmadhuss","email":"ahmadhussnain787@gmail.com"}],"readme":"# @aizvi/auth-sqlite\n\nA SQLite storage adapter for [`@aizvi/auth`](https://www.npmjs.com/package/@aizvi/auth).\nPoint it at a `.sqlite` file, or a database connection you already have, and\nyour auth system has somewhere to store users and sessions. No separate\ndatabase server needed.\n\nIt creates its own `users` and `mobile_auth_sessions` tables the first time\nit runs, and never touches anything else in your database.\n\n## Install\n\n```bash\nnpm install @aizvi/auth @aizvi/auth-sqlite\npnpm add @aizvi/auth @aizvi/auth-sqlite\nyarn add @aizvi/auth @aizvi/auth-sqlite\nbun add @aizvi/auth @aizvi/auth-sqlite\n```\n\n## Quick start\n\nThe easiest way to use this package: give it a file path, and it opens (or\ncreates) the database for you.\n\n```ts\nimport { createAuthRouter } from '@aizvi/auth';\nimport { sqliteAdapter } from '@aizvi/auth-sqlite';\n\napp.use(\n  '/auth',\n  createAuthRouter({\n    adapter: sqliteAdapter({ file: './data.sqlite' }),\n    mailer: myEmailSender,\n    jwtSecret: process.env.JWT_SECRET!,\n  })\n);\n```\n\nThe file, and any missing parent directories, is created automatically if it\ndoesn't already exist, with `journal_mode = WAL` and `foreign_keys = ON` set\nfor you.\n\n### Which driver does this use?\n\n`sqliteAdapter()` picks the right driver automatically based on where your\ncode is running, so you never have to think about it:\n\n- Running under **Bun**: uses Bun's built in [`bun:sqlite`](https://bun.sh/docs/api/sqlite).\n- Running under **Node.js**: uses [`better-sqlite3`](https://github.com/WiseLibs/better-sqlite3).\n\nSame function, same behavior, either way. Nothing in your code needs to\nchange if you switch runtimes.\n\n## Already have a SQLite connection? Use that instead\n\nIf your app already opens its own SQLite connection, for example with\nNode's built in [`node:sqlite`](https://nodejs.org/api/sqlite.html), or a\n`better-sqlite3` instance configured with your own options, you don't need\n`sqliteAdapter()` to open a second one. Hand your existing connection\nstraight to `createSqliteAuthAdapter()` instead:\n\n```ts\nimport { DatabaseSync } from 'node:sqlite';\nimport { createAuthRouter } from '@aizvi/auth';\nimport { createSqliteAuthAdapter } from '@aizvi/auth-sqlite';\n\nconst db = new DatabaseSync('./data.sqlite'); // the connection your app already uses\ndb.exec('PRAGMA journal_mode = WAL');\ndb.exec('PRAGMA foreign_keys = ON');\n\napp.use(\n  '/auth',\n  createAuthRouter({\n    adapter: createSqliteAuthAdapter(db),\n    mailer: myEmailSender,\n    jwtSecret: process.env.JWT_SECRET!,\n  })\n);\n```\n\nThis works with any driver that can `exec()` SQL, `prepare()` a statement,\nand `run()` or `get()` it, which covers `node:sqlite`, `better-sqlite3`, and\n`bun:sqlite`. That way you only ever have one open connection to your\ndatabase, shared between your auth tables and everything else your app\nstores.\n\nIf you're adding auth to an app that already has its own `users` table with\nthe same columns this package expects (see [Schema](#schema) below),\n`createSqliteAuthAdapter()` simply uses it as is. It only creates the tables\nif they don't already exist.\n\n### More examples\n\n**Using `better-sqlite3` with your own options, instead of the defaults\n`sqliteAdapter()` picks:**\n\n```ts\nimport Database from 'better-sqlite3';\nimport { createSqliteAuthAdapter } from '@aizvi/auth-sqlite';\n\nconst db = new Database('./data.sqlite', { timeout: 5000, readonly: false });\ndb.pragma('journal_mode = WAL');\n\nconst adapter = createSqliteAuthAdapter(db);\n```\n\n**Sharing one connection between auth and the rest of your app:**\n\n```ts\nimport { DatabaseSync } from 'node:sqlite';\nimport { createSqliteAuthAdapter } from '@aizvi/auth-sqlite';\n\n// Your app's single, shared database connection, used everywhere.\nexport const db = new DatabaseSync('./data.sqlite');\ndb.exec('PRAGMA journal_mode = WAL');\ndb.exec('PRAGMA foreign_keys = ON');\n\n// Your own tables, created however you already do it.\ndb.exec('CREATE TABLE IF NOT EXISTS posts (id TEXT PRIMARY KEY, title TEXT NOT NULL)');\n\n// The auth adapter reuses the exact same connection and file.\nexport const authAdapter = createSqliteAuthAdapter(db);\n```\n\n**Running the migration yourself, ahead of time:**\n\n```ts\nimport { DatabaseSync } from 'node:sqlite';\nimport { migrate, createSqliteAuthAdapter } from '@aizvi/auth-sqlite';\n\nconst db = new DatabaseSync('./data.sqlite');\nmigrate(db); // creates users / mobile_auth_sessions if they don't exist yet\n\n// ...later, once you're ready to build the router:\nconst adapter = createSqliteAuthAdapter(db);\n```\n\n## Schema\n\nOn first use, this creates:\n\n```sql\nCREATE TABLE IF NOT EXISTS users (\n  id TEXT PRIMARY KEY,\n  email TEXT UNIQUE NOT NULL,\n  password_hash TEXT NOT NULL,\n  is_verified INTEGER NOT NULL DEFAULT 0,\n  verification_code TEXT,\n  verification_expires TEXT,\n  reset_code TEXT,\n  reset_expires TEXT,\n  created_at TEXT NOT NULL,\n  updated_at TEXT NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS mobile_auth_sessions (\n  id TEXT PRIMARY KEY,\n  user_id TEXT NOT NULL REFERENCES users(id),\n  refresh_token_hash TEXT NOT NULL,\n  expires_at TEXT NOT NULL,\n  revoked_at TEXT,\n  created_at TEXT NOT NULL,\n  updated_at TEXT NOT NULL\n);\n```\n\nOnly the SHA-256 hash of a refresh token is ever stored, never the raw token\nitself.\n\n## API\n\n### `sqliteAdapter(options)`\n\n| Option | Required | Description |\n| ------ | -------- | ----------- |\n| `file` | yes      | Path to the SQLite file. Created automatically, including parent directories, if it doesn't exist. |\n\nReturns an adapter ready to pass to `createAuthRouter`. Also has a\n`.close()` method if you need to close the connection manually. Most apps\nnever need to call this.\n\n### `createSqliteAuthAdapter(db)`\n\nTakes an already open database connection (anything implementing `exec`,\n`prepare().run()`/`.get()`, and `close()`; see [`src/driver.ts`](./src/driver.ts)\nfor the exact minimal interface) and returns the same kind of adapter.\n\n### `migrate(db)`\n\nRuns the table creation step on its own, if you want to control exactly\nwhen it happens rather than letting `sqliteAdapter`/`createSqliteAuthAdapter`\nrun it for you automatically.\n\n## Code of Conduct\n\nSee [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md).\n\n## License\n\nMIT (see [license.txt](./license.txt))\n","readmeFilename":"README.md"}