From 19c9683e2126c68cb9d231293162c756d69c51fb Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Thu, 8 Feb 2018 10:41:16 -0500 Subject: WIP --- backend/src/utils.js | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'backend/src/utils.js') 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, }; -- cgit v1.3