Wrong filename

This commit is contained in:
Clayton Wilson 2019-09-29 21:52:25 -04:00 committed by GitHub
parent ce8ee36354
commit f4ef1ee8e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);
})
};