diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-04-12 16:31:01 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-04-12 16:31:01 -0400 |
| commit | 97b6de6aa437f7a913a33b9e6aa18a919faf2caf (patch) | |
| tree | 431e12a535baf1d2ad59601ee7c5e8084ae7a263 /backend/src/utils.js | |
| parent | d22616d5a675f5a381c741784333151255713b45 (diff) | |
a whole bunch of things that should be in their own commits
Diffstat (limited to 'backend/src/utils.js')
| -rw-r--r-- | backend/src/utils.js | 35 |
1 files changed, 1 insertions, 34 deletions
diff --git a/backend/src/utils.js b/backend/src/utils.js index 2988b3d..faf028b 100644 --- a/backend/src/utils.js +++ b/backend/src/utils.js @@ -1,16 +1,3 @@ -const jwt = require('jsonwebtoken'); - -function getUserId(ctx) { - const Authorization = ctx.request.get('Authorization'); - if (Authorization) { - const token = Authorization.replace('Bearer ', ''); - const { userId } = jwt.verify(token, process.env.APP_SECRET); - return userId; - } - // TODO: Don't throw when they aren't logged in - // throw new Error('Sorry, you must be logged in to do that!'); -} - function hasPermission(user, permissionsNeeded) { const matchedPermissions = user.permissions.filter(permissionTheyHave => permissionsNeeded.includes(permissionTheyHave) @@ -27,24 +14,4 @@ function hasPermission(user, permissionsNeeded) { } } -function checkForUserId(ctx) { - const Authorization = ctx.request.get('Authorization'); - if (Authorization) { - const token = Authorization.replace('Bearer ', ''); - const { userId } = jwt.verify(token, process.env.APP_SECRET); - return userId; - } -} - -class AuthError extends Error { - constructor() { - super('Not authorized'); - } -} - -module.exports = { - getUserId, - AuthError, - checkForUserId, - hasPermission, -}; +exports.hasPermission = hasPermission; |
