1
0
mirror of https://github.com/sasjs/server.git synced 2026-01-06 14:10:06 +00:00

chore: code refactor

This commit is contained in:
2022-08-02 22:16:41 +05:00
parent 68515f95a6
commit f978814ca7
3 changed files with 42 additions and 29 deletions

View File

@@ -5,7 +5,7 @@ import {
PermissionSettingForRoute,
PermissionType
} from '../controllers/permission'
import { getPath } from '../utils'
import { getPath, isPublicRoute } from '../utils'
export const authorize: RequestHandler = async (req, res, next) => {
const { user } = req
@@ -17,6 +17,9 @@ export const authorize: RequestHandler = async (req, res, next) => {
// no need to check for permissions when user is admin
if (user.isAdmin) return next()
// no need to check for permissions when route is Public
if (await isPublicRoute(req)) return next()
const dbUser = await User.findOne({ id: user.userId })
if (!dbUser) return res.sendStatus(401)