So I’m using Replit Authentication and creating a Chat Room. Note: Authentication is on. This is my code:
app.get('/', (req, res) => {
const user = getUserInfo(req);
if (user) {
res.render('index.html', { username: user.name });
console.log(user.name + " joined.");
} else {
res.render('index.html', { username: "Guest" + getRandomInt(500) });
console.log("User not authenticated; Using Guest Process.);
}
});
For some reason, my webview is logged in, so the username comes up as doxr. When I open the website on a new tab, I’m not signed in and Replit is not giving me the Automatic sign-in page. What do I do?
You might want to check if there are the Replit auth headers that tell you who is signed in. Then if they don’t exist, force them to log in. That or you use repl-auth as @9pfs1 suggested.
I’m no Node JS expert but uh yeah no that is not going to work. That’s not how you check a header. I think you can do this because that’s how it works in Python Flask but I have not tested it.
You’re trying to run frontend JS in the backend, so no, that will not work. (window won’t work in the backend, the app object won’t exist in the frontend, and X-Replit-User- will throw a syntax error.)
Just something im noticing; incase that two ‘Guests’ have the name number, this could cause conflict if your website relies on the username… try tracking (using database to store guest numbers) the already used gust numbers and keep rolling numbers until one is found.