I'm trying to make it so my remote ban system picks up as soon as the user is added to the database, because right now they have to rejoin the game in order for it to work
I know some people will say "just use a while loop" however this is bad as it can overwhelm the api.
Here is my api checkifbanned and ban route
app.get('/checkuser', validateAPIKey, async (req, res) => {
const requestedUserId = req.query.userid;
try {
const result = await collection.findOne({ userid: requestedUserId });
if (result) {
const { reason } = result;
res.json({ Banned: true, reason });
} else {
res.json({ Banned: false, reason: null });
}
} catch (error) {
console.error('Error while checking value:', error);
res.status(500).json({ error: 'Internal server error' });
}
});
app.post('/ban', async (req, res) => {
const { notapikeylol, userid, usernametoinsert, reason } = req.body;
if (notapikeylol !== "hotdog123") {
return res.status(401).json({ error: 'Invalid API key' });
}
axios
.get(`https://api.newstargeted.com/roblox/users/v2/user.php?userId=${userid}`)
.then(async (response) => {
console.log(response.data);
const usernametoinsert = response.data.username;
try {
const result = await insertUserData(userid, usernametoinsert, reason);
res.json({ success: true, insertedCount: result.insertedCount });
} catch (error) {
console.error('Error while inserting user:', error);
res.status(500).json({ error: 'Internal server error' });
}
})
.catch((error) => {
console.error(`Error: ${error.message}`);
res.status(500).json({ error: 'Internal server error' });
});
});
async function insertUserData(userid, usernametoinsert, reason) {
const result = await collection.insertOne({ userid, usernametoinsert, reason });
return result;
}
