Home > OS >  How to redirect user to home page after login (JS, HTML)
How to redirect user to home page after login (JS, HTML)

Time:10-27

i tried to create (my first) login page, i did communication between client and server with WebSocket in JS, it check credentials of user (Token that makes you login to page). Only thing that i can't figure out is how to redirect user to other page, with sure that, he will be logged into this account and to protect from not authorized users. (server -> (JS) nodemon, client -> JS, HTML, CSS)

I expect that someone will make this topic clear to me, and explain how to code it :)

CodePudding user response:

I'm also new to js. but I thing the way you can do this by using window.location.href = "homepage.html"

steps

  1. create a homepage.html file
  2. on successful login attempt redirect user to hompage.html file by window.location.href = "homepage.html"
  3. on homepage load you will check if user's valid token is saved or not( or by whatever method you are authenticating a user) if user is authenticated user then show him homepage's content otherwise redirect him ho login.html page.( will be used to prevent if user trys to access homepage.html directly by entering url in search bar)

I hope this answers your question. :)

CodePudding user response:

window.location.href = "/";
  • Related