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
This commit is contained in:
alphaeusmote
2025-04-08 20:51:26 +00:00
parent baf4844915
commit 589fa3cc8d
2 changed files with 9 additions and 2 deletions
+1 -1
View File
@@ -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();
}
+8 -1
View File
@@ -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();
}