From 589fa3cc8d53d982c7de3abcd32c7f4c0d429a3f Mon Sep 17 00:00:00 2001 From: alphaeusmote <41258468-alphaeusmote@users.noreply.replit.com> Date: Tue, 8 Apr 2025 20:51:26 +0000 Subject: [PATCH] Fix authentication error causing 500 error by adding check for isAuthenticated function existence. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 705f2157-ef97-4fbd-89e4-8c7f2ecaea90 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7ed01c5f-a82d-405a-b728-b2e3d127c60c/f23c0b09-ba7a-43a9-b8cd-a87451662495.jpg --- server/authorization.ts | 2 +- server/ldap-query-builder-routes.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/server/authorization.ts b/server/authorization.ts index 07eb575..6d71dc3 100644 --- a/server/authorization.ts +++ b/server/authorization.ts @@ -17,7 +17,7 @@ export type RequirePermissionOptions = RequireAuthOptions & { export function requireAuth(options: RequireAuthOptions = {}) { return async (req: Request, res: Response, next: NextFunction) => { // Check for session authentication - if (req.isAuthenticated()) { + if (typeof req.isAuthenticated === 'function' && req.isAuthenticated()) { return next(); } diff --git a/server/ldap-query-builder-routes.ts b/server/ldap-query-builder-routes.ts index e23fb8e..e4e8df7 100644 --- a/server/ldap-query-builder-routes.ts +++ b/server/ldap-query-builder-routes.ts @@ -14,7 +14,14 @@ import { InsertLdapQuery, LdapQuery, InsertLdapQueryVersion } from "@shared/sche function hasPermission(permission: string) { return (req: any, res: any, next: any) => { // Check if the user is authenticated via passport session or has a valid API token - if (req.user || req.headers.authorization) { + if ( + // Check for authenticated session (safely check if isAuthenticated is a function first) + (typeof req.isAuthenticated === 'function' && req.isAuthenticated()) || + // Or check for existing user object (set by token auth) + req.user || + // Or check for authorization header (token auth) + req.headers.authorization + ) { // In a real implementation, this would check the user's permissions against the required permission return next(); }