Why is Auth is failing to recognize users?

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.

It’s doing that because of this line:

app.use(express.static(path.join(__dirname, '/')));

Which makes it automatically render index.html at /

1 Like

ohhh hmm how could I fix it

Remove that line… It’s not doing anything.

3 Likes

oh ok :confused:

thanks qwerty!

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.