mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 02:08:47 +00:00
Add comments to fbAuth.js
This commit is contained in:
parent
f4ef1ee8e1
commit
dc498a3a1d
@ -1,7 +1,12 @@
|
||||
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, res, next) => {
|
||||
let idToken;
|
||||
|
||||
// Checking that the token exists in the header of the request
|
||||
if (req.headers.authorization) {
|
||||
idToken = req.headers.authorization;
|
||||
} else {
|
||||
@ -9,6 +14,7 @@ module.exports = (req, res, next) => {
|
||||
return res.status(403).json({ error: 'Unauthorized'});
|
||||
}
|
||||
|
||||
// Checking that the token is valid in firebase
|
||||
admin.auth().verifyIdToken(idToken)
|
||||
.then((decodedToken) => {
|
||||
req.user = decodedToken;
|
||||
@ -17,7 +23,7 @@ module.exports = (req, res, next) => {
|
||||
.get();
|
||||
})
|
||||
.then((data) => {
|
||||
req.user.handle = data.docs[0].data().handle;
|
||||
req.user.handle = data.docs[0].data().handle; // Save username
|
||||
req.user.imageUrl = data.docs[0].data().imageUrl;
|
||||
return next();
|
||||
})
|
||||
@ -25,4 +31,4 @@ module.exports = (req, res, next) => {
|
||||
console.error('Error while verifying token ', err);
|
||||
return res.status(403).json(err);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user