My code is sending the index file to both blacklisted and whitelisted people. It just kinda gives everybody index.html without checking. It’s not a problem with the code, I checked with Phind (GPT-4) and by myself.
Here is the code:
const users = ['not-ethan', 'doxr'];
app.get('/', (req, res) => {
const user = getUserInfo(req);
if (users.includes(user.name)) {
console.log(`Serving 403.html to user: ${user}`);
res.sendFile('/403.html', { root: path.join(__dirname, './') });
} else {
console.log(`Serving index.html to user: ${user}`);
res.sendFile('/index.html', { root: path.join(__dirname, './') });
}
});
app.listen(3000, () => console.log(`Port 3000`));
Weirdly, this still sends me to index.html. If anyone knows what the error is then please post. The code is probably the problem but I don’t know.
https://replit.com/@doxr/test-auth-fails#index.js
Made a repl if you want to check it out.