mega updates to things

This commit is contained in:
user
2026-02-28 15:54:51 +02:00
parent 57fbb4ab00
commit 4d107c8cab
8 changed files with 82 additions and 76 deletions

View File

@@ -4,10 +4,10 @@ import { hashString, verifyHash } from "@/core/hash.utils";
import { twoFactor, twofaSessions } from "@pkg/db/schema";
import { TwoFactor, type TwoFaSession } from "./data";
import { and, Database, eq, gt, lt } from "@pkg/db";
import { generateSecret, verify } from "otplib";
import { settings } from "@core/settings";
import type { Err } from "@pkg/result";
import { twofaErrors } from "./errors";
import { authenticator } from "otplib";
import { logger } from "@pkg/logger";
import { Redis } from "@pkg/redis";
import { nanoid } from "nanoid";
@@ -30,7 +30,7 @@ export class TwofaRepository {
) {}
checkTotp(secret: string, code: string) {
const checked = authenticator.verify({ secret, token: code });
const checked = verify({ secret, token: code });
logger.debug("TOTP check result", { checked });
return checked;
}
@@ -103,7 +103,7 @@ export class TwofaRepository {
return ResultAsync.fromSafePromise(
(async () => {
const secret = authenticator.generateSecret();
const secret = generateSecret();
const payload = {
secret,
lastUsedCode: "",
@@ -546,7 +546,7 @@ export class TwofaRepository {
() =>
twofaErrors.dbError(fctx, "Failed to cleanup expired sessions"),
).map((result) => {
const count = result.rowCount || 0;
const count = result.length || 0;
logger.info("Expired sessions cleaned up", { ...fctx, count });
return count;
});