mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2026-03-10 21:25:04 +00:00
added folders to organize files
This commit is contained in:
28
functions/util/fbAuth.js
Normal file
28
functions/util/fbAuth.js
Normal file
@@ -0,0 +1,28 @@
|
||||
const { admin, db } = require('./admin');
|
||||
|
||||
module.exports = (req, res, next) => {
|
||||
let idToken;
|
||||
if (req.headers.authorization) {
|
||||
idToken = req.headers.authorization;
|
||||
} else {
|
||||
console.error('No token found');
|
||||
return res.status(403).json({ error: 'Unauthorized'});
|
||||
}
|
||||
|
||||
admin.auth().verifyIdToken(idToken)
|
||||
.then((decodedToken) => {
|
||||
req.user = decodedToken;
|
||||
return db.collection('users').where('userId', '==', req.user.uid)
|
||||
.limit(1)
|
||||
.get();
|
||||
})
|
||||
.then((data) => {
|
||||
req.user.handle = data.docs[0].data().handle;
|
||||
req.user.imageUrl = data.docs[0].data().imageUrl;
|
||||
return next();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Error while verifying token ', err);
|
||||
return res.status(403).json(err);
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user