fix(lint): Add ctx shim to routes/auth/totp

- Add credentialManager, totpConfig, saveTotpConfig, session to deps
- Create ctx shim for backward compatibility
- Fix hasOwnProperty anti-pattern (use Object.prototype.hasOwnProperty.call)

Result: 54 errors → 0 errors
This commit is contained in:
Krystie
2026-03-29 22:37:21 -07:00
parent 5baa97bbf9
commit a86546181e
3 changed files with 29 additions and 3 deletions

View File

@@ -18,6 +18,7 @@ module.exports = function(ctx) {
authManager: ctx.authManager,
credentialManager: ctx.credentialManager,
totpConfig: ctx.totpConfig,
saveTotpConfig: ctx.saveTotpConfig,
session: ctx.session,
asyncHandler: ctx.asyncHandler,
errorResponse: ctx.errorResponse,

View File

@@ -2,17 +2,29 @@ const express = require('express');
const { renewCSRFToken } = require('../../csrf-protection');
const { ValidationError, AuthenticationError } = require('../../errors');
module.exports = function({ authManager, asyncHandler, errorResponse, log }) {
const router = express.Router();
/**
* Auth TOTP routes factory
* @param {Object} deps - Explicit dependencies
* @param {Object} deps.authManager - Auth manager
* @param {Object} deps.credentialManager - Credential manager
* @param {Object} deps.totpConfig - TOTP configuration
* @param {Function} deps.saveTotpConfig - Save TOTP config helper
* @param {Object} deps.session - Session context
* @param {Function} deps.asyncHandler - Async route handler wrapper
* @param {Function} deps.errorResponse - Error response helper
* @param {Object} deps.log - Logger instance
* @returns {express.Router}
*/
module.exports = function({ authManager, credentialManager, totpConfig, saveTotpConfig, session, asyncHandler, errorResponse, log }) {
const router = express.Router();
// Ctx shim for backward compatibility
const ctx = {
credentialManager,
totpConfig,
saveTotpConfig,
session
};
// Get current TOTP config (public route)
router.get('/totp/config', asyncHandler(async (req, res) => {
@@ -181,7 +193,7 @@ module.exports = function({ authManager, asyncHandler, errorResponse, log }) {
router.post('/totp/config', asyncHandler(async (req, res) => {
const { sessionDuration } = req.body;
if (sessionDuration && !ctx.session.durations.hasOwnProperty(sessionDuration)) {
if (sessionDuration && !Object.prototype.hasOwnProperty.call(ctx.session.durations, sessionDuration)) {
throw new ValidationError(`Invalid session duration. Valid options: ${Object.keys(ctx.session.durations).join(', ')}`, 'sessionDuration');
}