Replit auth in nodejs?

If I understand correctly, I did that in node.js at https://replit.com/@doxr/SchoolHub

so maybe this is the code you’re looking for:

const HTTPS = process.env['html']; // The HTML is in a secret so nobody can get it
const users = require('./users.json');

app.get('/', (req, res) => {
  const user = getUserInfo(req); // Repl Auth
  if (users.allowedUsers.includes(user.name)) {
    // User is allowed, send HTTPS content
    res.send(HTTPS);
  } else {
    // User is not allowed, send 403 rickroll page
    res.sendFile('/403.html', {
      root: path.join(__dirname, './')
    });
  }
});

for example, this is what users.json looked like

{
  "allowedUsers": [
    "doxr",
    "amasad",
    "totallygoogledrive"
  ]
}

the HTML part is optional (it’s what i used to secure index.html) but if you’ll send a file I’m pretty sure you have to change res.send(); because HTTPS variable looked like this:

<html>
<head>
<title>no</title>
</head>
</html>

The main idea is that it’s just HTML, not a way to send a file

3 Likes