mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-17 02:38: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');
|
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) => {
|
module.exports = (req, res, next) => {
|
||||||
let idToken;
|
let idToken;
|
||||||
|
|
||||||
|
// Checking that the token exists in the header of the request
|
||||||
if (req.headers.authorization) {
|
if (req.headers.authorization) {
|
||||||
idToken = req.headers.authorization;
|
idToken = req.headers.authorization;
|
||||||
} else {
|
} else {
|
||||||
@ -9,6 +14,7 @@ module.exports = (req, res, next) => {
|
|||||||
return res.status(403).json({ error: 'Unauthorized'});
|
return res.status(403).json({ error: 'Unauthorized'});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checking that the token is valid in firebase
|
||||||
admin.auth().verifyIdToken(idToken)
|
admin.auth().verifyIdToken(idToken)
|
||||||
.then((decodedToken) => {
|
.then((decodedToken) => {
|
||||||
req.user = decodedToken;
|
req.user = decodedToken;
|
||||||
@ -17,7 +23,7 @@ module.exports = (req, res, next) => {
|
|||||||
.get();
|
.get();
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.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;
|
req.user.imageUrl = data.docs[0].data().imageUrl;
|
||||||
return next();
|
return next();
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user