rename super user to admin and middleware refactoring

This commit is contained in:
Milo Schwartz
2024-11-05 22:38:57 -05:00
parent 7b755a273c
commit 03051878ef
26 changed files with 790 additions and 529 deletions

View File

@@ -25,7 +25,7 @@ export type VerifyTotpResponse = {
export async function verifyTotp(
req: Request,
res: Response,
next: NextFunction,
next: NextFunction
): Promise<any> {
const parsedBody = verifyTotpBody.safeParse(req.body);
@@ -33,8 +33,8 @@ export async function verifyTotp(
return next(
createHttpError(
HttpCode.BAD_REQUEST,
fromError(parsedBody.error).toString(),
),
fromError(parsedBody.error).toString()
)
);
}
@@ -46,8 +46,8 @@ export async function verifyTotp(
return next(
createHttpError(
HttpCode.BAD_REQUEST,
"Two-factor authentication is already enabled",
),
"Two-factor authentication is already enabled"
)
);
}
@@ -55,13 +55,17 @@ export async function verifyTotp(
return next(
createHttpError(
HttpCode.BAD_REQUEST,
"User has not requested two-factor authentication",
),
"User has not requested two-factor authentication"
)
);
}
try {
const valid = await verifyTotpCode(code, user.twoFactorSecret, user.userId);
const valid = await verifyTotpCode(
code,
user.twoFactorSecret,
user.userId
);
let codes;
if (valid) {
@@ -101,8 +105,8 @@ export async function verifyTotp(
return next(
createHttpError(
HttpCode.INTERNAL_SERVER_ERROR,
"Failed to verify two-factor authentication code",
),
"Failed to verify two-factor authentication code"
)
);
}
}