Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/server/src/enterprise/controllers/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const getAllPermissions = async (req: Request, res: Response, next: NextFunction
const allPermissions = appServer.identityManager.getPermissions().toJSON()
const user = req.user as LoggedInUser

if (!user) {
return res.status(StatusCodes.UNAUTHORIZED).json({ message: 'Unauthorized' })
}
Comment on lines 11 to +16
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Moving the authentication check before the permissions serialization avoids unnecessary processing for unauthenticated requests. This is particularly beneficial for endpoints that might be exposed to unauthenticated traffic. Additionally, using loose equality (== null) is the standard idiom for nullish checks in this project as per the general rules.

        const user = req.user as LoggedInUser
        if (user == null) {
            return res.status(StatusCodes.UNAUTHORIZED).json({ message: 'Unauthorized' })
        }
        const allPermissions = appServer.identityManager.getPermissions().toJSON()
References
  1. In JavaScript/TypeScript, use loose equality (== null) as a standard idiom for a 'nullish' check that covers both null and undefined.


let permissions: { [key: string]: { key: string; value: string }[] } = allPermissions

// Mapping of feature flags to permission prefixes
Expand Down