v1.5.1/release

This commit is contained in:
2020-07-25 20:07:16 -04:00
parent df100fef63
commit 74357d97d3
24 changed files with 703 additions and 10 deletions
+42
View File
@@ -0,0 +1,42 @@
const admin = require('firebase-admin');
module.exports = (req, res, next) => {
res.set('Access-Control-Allow-Origin', ['*']);
if (req.method === 'OPTIONS') {
res.status(200).send();
return next();
}
if (req.headers.authorization) {
try {
const token = req.headers.authorization.split(' ')[1];
const reqToken = token.split(':')[0];
const reqUid = token.split(':')[1];
admin
.auth()
.verifyIdToken(reqToken)
.then((user) => {
if (user.uid === reqUid) {
console.info('Verified Token - UID - ', reqUid);
if (req.method === 'POST') {
const bodydata = JSON.parse(req.body);
bodydata.uid = user.uid;
req.body = JSON.stringify(bodydata);
}
if (req.method === 'GET' || req.method === 'DELETE') {
req.body = JSON.stringify({ uid: user.uid });
}
return next();
} else {
return res.status(401).send({ message: 'Unauthorized' });
}
})
.catch((err) => {
console.error('Failed Auth - ', req.headers.authorization, '\n', err);
return res.status(500).send({ message: 'Unable to verify user token' });
});
} catch (err) {
console.log(err);
return res.status(401).send({ message: 'Something went wrong when authorizing' });
}
} else return res.status(401).send({ message: 'Got no user token' });
};