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:
@@ -18,6 +18,7 @@ module.exports = function(ctx) {
|
|||||||
authManager: ctx.authManager,
|
authManager: ctx.authManager,
|
||||||
credentialManager: ctx.credentialManager,
|
credentialManager: ctx.credentialManager,
|
||||||
totpConfig: ctx.totpConfig,
|
totpConfig: ctx.totpConfig,
|
||||||
|
saveTotpConfig: ctx.saveTotpConfig,
|
||||||
session: ctx.session,
|
session: ctx.session,
|
||||||
asyncHandler: ctx.asyncHandler,
|
asyncHandler: ctx.asyncHandler,
|
||||||
errorResponse: ctx.errorResponse,
|
errorResponse: ctx.errorResponse,
|
||||||
|
|||||||
@@ -2,17 +2,29 @@ const express = require('express');
|
|||||||
const { renewCSRFToken } = require('../../csrf-protection');
|
const { renewCSRFToken } = require('../../csrf-protection');
|
||||||
const { ValidationError, AuthenticationError } = require('../../errors');
|
const { ValidationError, AuthenticationError } = require('../../errors');
|
||||||
|
|
||||||
module.exports = function({ authManager, asyncHandler, errorResponse, log }) {
|
|
||||||
const router = express.Router();
|
|
||||||
/**
|
/**
|
||||||
* Auth TOTP routes factory
|
* Auth TOTP routes factory
|
||||||
* @param {Object} deps - Explicit dependencies
|
* @param {Object} deps - Explicit dependencies
|
||||||
* @param {Object} deps.authManager - Auth manager
|
* @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.asyncHandler - Async route handler wrapper
|
||||||
* @param {Function} deps.errorResponse - Error response helper
|
* @param {Function} deps.errorResponse - Error response helper
|
||||||
* @param {Object} deps.log - Logger instance
|
* @param {Object} deps.log - Logger instance
|
||||||
* @returns {express.Router}
|
* @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)
|
// Get current TOTP config (public route)
|
||||||
router.get('/totp/config', asyncHandler(async (req, res) => {
|
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) => {
|
router.post('/totp/config', asyncHandler(async (req, res) => {
|
||||||
const { sessionDuration } = req.body;
|
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');
|
throw new ValidationError(`Invalid session duration. Valid options: ${Object.keys(ctx.session.durations).join(', ')}`, 'sessionDuration');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
13
fix-ctx-routes.sh
Normal file
13
fix-ctx-routes.sh
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Systematically fix ctx.* references in all route files
|
||||||
|
|
||||||
|
cd /root/.openclaw/agents/main/workspace/dashcaddy-work/dashcaddy-api
|
||||||
|
|
||||||
|
# Find all route files with ctx errors
|
||||||
|
echo "Finding routes with ctx errors..."
|
||||||
|
for file in $(find routes -name "*.js" -type f | grep -v index.js | grep -v helpers.js); do
|
||||||
|
errors=$(npx eslint "$file" 2>&1 | grep -c "'ctx' is not defined")
|
||||||
|
if [ "$errors" -gt 0 ]; then
|
||||||
|
echo "$errors errors in $file"
|
||||||
|
fi
|
||||||
|
done | sort -rn
|
||||||
Reference in New Issue
Block a user