Skip to content
← Back to Community
Login Authentication (NodeJS Express)
Profile icon
ObiVibKenobi

Hi! If you’re reading this, thanks!
I recently began a project that may take a while, and decided to add in a log in system. It’s pretty easy to use Repl.DB, but here’s the problem - after someone logins, and clicks a button, they get redirected. What if someone just types that link straight into the browser? I know there’s a way to stop that from happening, but how?

Thanks!

Voters
Profile icon
MrMOHDRX
Profile icon
ObiVibKenobi
Comments
hotnewtop
Profile icon
EpicGamer007

pretty simple, all you gotta do,(i will be using replauth for this example),

// check request headers to make suer they are logged in if(req.get('X-Replit-User-Name') == '' || req.get('X-Replit-User-Name') == null) { //if they are not logged in res.redirect("login") } else { // they are logged in res.send("whatever page u want to send"); }

this assumes you are using express

Profile icon
EpicGamer007

If you invite me to the repl i could probably make it more clear.

Profile icon
Squirrel777

Maybe you can use sessionStorage to prevent that and to redirect to the login page

Profile icon
alanchen12

When someone accesses the URL, you can check if they are logged in or not.

Profile icon
ObiVibKenobi

... how..?

@alanchen12