From cf834c8078b743c10a0070e735224bc55ff8b5f1 Mon Sep 17 00:00:00 2001 From: devmrh Date: Wed, 29 Dec 2021 12:06:03 +0330 Subject: [PATCH] make sure routeInfo object is ready to avoid root path error --- lib/guard.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/guard.js b/lib/guard.js index 9853f67..542c5e1 100644 --- a/lib/guard.js +++ b/lib/guard.js @@ -1,9 +1,9 @@ function guard (path, user, options) { const routeInfo = options.routes.match(path) - const given = (user && user.scope) || [] - const required = routeInfo.scope + const given = (user && user?.scope) || [] + const required = routeInfo?.scope - if (routeInfo.auth === false || required.find(s => given.includes(s))) { + if (!routeInfo || routeInfo.auth === false || required.find(s => given.includes(s))) { return options.grant && options.grant() }