v1.4.3/fix restore admin on join
This commit is contained in:
@@ -23,6 +23,7 @@ module.exports = async (req, res) => {
|
||||
player: bodydata.player,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
adminUid: bodydata.uid,
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ message: 'Unable to start party.' });
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
const admin = require('firebase-admin');
|
||||
const { firestore } = require('firebase-admin');
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
const bodydata = JSON.parse(req.body);
|
||||
console.log('Requested Join - UID - ', bodydata.uid, '\n\tRoom - ', bodydata.partyName);
|
||||
// GET ROOM EXISTS, ROOM SOURCE, & ROOM PIN
|
||||
const [exists, roomSource, roomPin] = await admin
|
||||
const [exists, roomSource, roomPin, adminUid] = await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(bodydata.partyName)
|
||||
@@ -13,6 +14,7 @@ module.exports = async (req, res) => {
|
||||
roomSnap.exists,
|
||||
roomSnap.exists ? roomSnap.data().player.source : '',
|
||||
roomSnap.exists ? roomSnap.data().pin : '',
|
||||
roomSnap.exists ? roomSnap.data().adminUid : '',
|
||||
])
|
||||
.catch((err) => {
|
||||
console.error(
|
||||
@@ -22,6 +24,18 @@ module.exports = async (req, res) => {
|
||||
});
|
||||
if (exists && roomPin !== bodydata.partyPin)
|
||||
return res.status(401).send({ message: 'Incorrect party pin' });
|
||||
if (adminUid === bodydata.uid) {
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(bodydata.partyName)
|
||||
.collection('users')
|
||||
.doc(bodydata.uid)
|
||||
.set({
|
||||
admin: true,
|
||||
name: bodydata.userName,
|
||||
});
|
||||
}
|
||||
// GET IF USER EXISTS AND IS ADMIN
|
||||
const [userExists, userAdmin, userName] = await admin
|
||||
.firestore()
|
||||
|
||||
Reference in New Issue
Block a user