This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { createHash, randomBytes, randomUUID, timingSafeEqual } from 'node:crypto';
|
||||
import { db } from '../db/index.js';
|
||||
import { ensureAuthSchema } from './schema.js';
|
||||
import { hashPassword, verifyPassword } from './passwords.js';
|
||||
import { systemUsername, type AuthUser, type UserRole } from '../../auth.js';
|
||||
|
||||
@@ -9,9 +8,7 @@ export const SESSION_LIFETIME_MS = 12 * 60 * 60_000;
|
||||
export const SESSION_IDLE_MS = 30 * 60_000;
|
||||
const digest = (value: string) => createHash('sha256').update(value).digest('hex');
|
||||
function database() {
|
||||
const handle = db();
|
||||
ensureAuthSchema(handle);
|
||||
return handle;
|
||||
return db();
|
||||
}
|
||||
type UserRow = {
|
||||
id: string;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type Database from 'better-sqlite3';
|
||||
const initialized = new WeakSet<Database.Database>();
|
||||
export function ensureAuthSchema(handle: Database.Database): void {
|
||||
if (initialized.has(handle)) return;
|
||||
export function migrateAuthSchema(handle: Database.Database): void {
|
||||
handle.exec(`
|
||||
CREATE TABLE IF NOT EXISTS auth_users (
|
||||
id TEXT PRIMARY KEY, username TEXT NOT NULL COLLATE NOCASE UNIQUE,
|
||||
@@ -24,5 +22,4 @@ export function ensureAuthSchema(handle: Database.Database): void {
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS auth_audit_created_at ON auth_audit(created_at);
|
||||
`);
|
||||
initialized.add(handle);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user