From f4ef1ee8e1b38cb204d414d8e3cd0fcd67b06b95 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Sun, 29 Sep 2019 21:52:25 -0400 Subject: [PATCH] Wrong filename --- functions/util/FBAuth.js | 35 ----------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 functions/util/FBAuth.js diff --git a/functions/util/FBAuth.js b/functions/util/FBAuth.js deleted file mode 100644 index e9ebf97..0000000 --- a/functions/util/FBAuth.js +++ /dev/null @@ -1,35 +0,0 @@ -const {admin, db} = require('./admin'); - -// Acts as a middleman between the client and any function that you use it with -// The function will only execute if the user is logged in, or rather, they have -// a valid token -module.exports = (req, resp, next) => { - let idToken; - - // Checking that the token exists in the header of the request - if (req.headers.authorization && req.headers.authorization.startsWith('Bearer ')) { - idToken = req.headers.authorization.split('Bearer ')[1]; - } else { - console.error('No token found'); - return resp.status(403).json({ error: 'Unauthorized' }); - } - - // Checking that the token is valid in firebase - admin.auth().verifyIdToken(idToken) - .then(decodedToken => { - req.user = decodedToken; - console.log(decodedToken); - return db.collection('users') - .where('userId', '==', req.user.uid) - .limit(1) - .get(); - }) - .then(data => { - req.user.handle = data.docs[0].data().handle; // Save username - return next(); - }) - .catch(err => { - console.error('Error verifying token', err); - return res.status(403).json(err); - }) -}; \ No newline at end of file