diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-02-08 10:41:16 -0500 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-02-08 10:41:16 -0500 |
| commit | 19c9683e2126c68cb9d231293162c756d69c51fb (patch) | |
| tree | 4679ca2dee47740aa0bf6fe623513c4242e027e6 /backend/src/utils.js | |
| parent | eabff7cd396d1f37ceb929e666f082ce57f07919 (diff) | |
WIP
Diffstat (limited to 'backend/src/utils.js')
| -rw-r--r-- | backend/src/utils.js | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/backend/src/utils.js b/backend/src/utils.js index 35587db..642c04a 100644 --- a/backend/src/utils.js +++ b/backend/src/utils.js @@ -11,6 +11,15 @@ function getUserId(ctx) { throw new AuthError(); } +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'); @@ -20,4 +29,5 @@ class AuthError extends Error { module.exports = { getUserId, AuthError, + checkForUserId, }; |
