From b12c743440baebb3baf9e357264bb626ef75c30a Mon Sep 17 00:00:00 2001 From: Lint Action Date: Sun, 9 Mar 2025 22:57:12 +0000 Subject: [PATCH] style: fix linting issues met ESLint --- backend/src/middleware/auth/auth.ts | 12 +++++------- backend/src/routes/auth.ts | 2 +- frontend/src/services/auth/auth-service.ts | 6 +++--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/backend/src/middleware/auth/auth.ts b/backend/src/middleware/auth/auth.ts index 9c988146..33b65662 100644 --- a/backend/src/middleware/auth/auth.ts +++ b/backend/src/middleware/auth/auth.ts @@ -12,7 +12,7 @@ const JWKS_CACHE = true; const JWKS_RATE_LIMIT = true; const REQUEST_PROPERTY_FOR_JWT_PAYLOAD = "jwtPayload"; const JWT_ALGORITHM = "RS256"; // Not configurable via env vars since supporting other algorithms would - // require additional libraries to be added. + // Require additional libraries to be added. const JWT_PROPERTY_NAMES = { username: "preferred_username", @@ -50,9 +50,9 @@ const verifyJwtToken = expressjwt({ throw new Error("Invalid token"); } - let issuer = (token.payload as JwtPayload).iss; + const issuer = (token.payload as JwtPayload).iss; - let idpConfig = Object.values(idpConfigs).find(config => config.issuer === issuer); + const idpConfig = Object.values(idpConfigs).find(config => config.issuer === issuer); if (!idpConfig) { throw new Error("Issuer not accepted."); } @@ -76,7 +76,7 @@ function getAuthenticationInfo(req: AuthenticatedRequest): AuthenticationInfo | if (!req.jwtPayload) { return; } - let issuer = req.jwtPayload.iss; + const issuer = req.jwtPayload.iss; let accountType: "student" | "teacher"; if (issuer === idpConfigs.student.issuer) { @@ -113,8 +113,7 @@ export const authenticateUser = [verifyJwtToken, addAuthenticationInfo]; * @param accessCondition Predicate over the current AuthenticationInfo. Access is only granted when this evaluates * to true. */ -export const authorize = (accessCondition: (auth: AuthenticationInfo) => boolean) => { - return (req: AuthenticatedRequest, res: express.Response, next: express.NextFunction): void => { +export const authorize = (accessCondition: (auth: AuthenticationInfo) => boolean) => (req: AuthenticatedRequest, res: express.Response, next: express.NextFunction): void => { if (!req.auth) { throw new UnauthorizedException(); } else if (!accessCondition(req.auth)) { @@ -123,7 +122,6 @@ export const authorize = (accessCondition: (auth: AuthenticationInfo) => boolean next(); } } -} /** * Middleware which rejects all unauthenticated users, but accepts all authenticated users. diff --git a/backend/src/routes/auth.ts b/backend/src/routes/auth.ts index 57af3a7d..76d7c347 100644 --- a/backend/src/routes/auth.ts +++ b/backend/src/routes/auth.ts @@ -3,7 +3,7 @@ import {getFrontendAuthConfig} from "../controllers/auth.js"; import {authenticatedOnly, studentsOnly, teachersOnly} from "../middleware/auth/auth.js"; const router = express.Router(); -// returns auth configuration for frontend +// Returns auth configuration for frontend router.get('/config', (req, res) => { res.json(getFrontendAuthConfig()); }); diff --git a/frontend/src/services/auth/auth-service.ts b/frontend/src/services/auth/auth-service.ts index a38d5f2a..fd9bd428 100644 --- a/frontend/src/services/auth/auth-service.ts +++ b/frontend/src/services/auth/auth-service.ts @@ -27,7 +27,7 @@ async function loadUser(): Promise { if (!activeRole) { return null; } - let user = await userManagers[activeRole].getUser(); + const user = await userManagers[activeRole].getUser(); authState.user = user; authState.accessToken = user?.access_token || null; authState.activeRole = activeRole || null; @@ -121,9 +121,9 @@ apiClient.interceptors.response.use( console.log("Access token expired, trying to refresh..."); await renewToken(); return apiClient(error.config!); // Retry the request - } else { // Apparently, the user got a 401 because he was not logged in yet at all. Redirect him to login. + } // Apparently, the user got a 401 because he was not logged in yet at all. Redirect him to login. await initiateLogin() - } + } return Promise.reject(error); }