mirror of
https://github.com/freedbygrace/ActiveDirectoryManager.git
synced 2026-08-19 14:57:03 +00:00
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:
@@ -17,7 +17,7 @@ export type RequirePermissionOptions = RequireAuthOptions & {
|
|||||||
export function requireAuth(options: RequireAuthOptions = {}) {
|
export function requireAuth(options: RequireAuthOptions = {}) {
|
||||||
return async (req: Request, res: Response, next: NextFunction) => {
|
return async (req: Request, res: Response, next: NextFunction) => {
|
||||||
// Check for session authentication
|
// Check for session authentication
|
||||||
if (req.isAuthenticated()) {
|
if (typeof req.isAuthenticated === 'function' && req.isAuthenticated()) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,14 @@ import { InsertLdapQuery, LdapQuery, InsertLdapQueryVersion } from "@shared/sche
|
|||||||
function hasPermission(permission: string) {
|
function hasPermission(permission: string) {
|
||||||
return (req: any, res: any, next: any) => {
|
return (req: any, res: any, next: any) => {
|
||||||
// Check if the user is authenticated via passport session or has a valid API token
|
// 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
|
// In a real implementation, this would check the user's permissions against the required permission
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user