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() }