23 lines
639 B
TypeScript
23 lines
639 B
TypeScript
/**
|
|
* Adds `users.tokens_valid_after`, so that changing a password ends every
|
|
* session opened before. Tokens are stateless JWTs, so lib/auth.ts refuses a
|
|
* token issued before that time instead.
|
|
*
|
|
* @module
|
|
*/
|
|
|
|
import type { DatabaseSync } from "node:sqlite";
|
|
|
|
/**
|
|
* Run once by `runMigrations`. Existing users start with NULL, which revokes no
|
|
* token.
|
|
*/
|
|
export function up(db: DatabaseSync): void {
|
|
const cols = db.prepare(`PRAGMA table_info(users);`).all() as {
|
|
name: string;
|
|
}[];
|
|
if (!cols.some((c) => c.name === "tokens_valid_after")) {
|
|
db.exec(`ALTER TABLE users ADD COLUMN tokens_valid_after TEXT;`);
|
|
}
|
|
}
|