I am building a website which requires authentication of user. I'm using React for that. How do I make secure login system? Everything I have is in localStorage. I'm afraid that with this solution, anyone can make own localStorage in their browser and use it to login and authenticate them as real users. Below is my login function:
login(){
if (typeof(Storage) !== "undefined") {
localStorage.setItem("userId",this.state.user._id);
localStorage.setItem("username", this.state.user.username);
localStorage.setItem("email", this.state.user.email);
localStorage.setItem("date", this.state.user.date);
this.setState({isLoggedIn: true});
localStorage.setItem("isLoggedIn", this.state.isLoggedIn);
if(localStorage.getItem("isLoggedIn")){
console.log("Congratulations "+localStorage.getItem("username")+", you are now logged in.");
setTimeout(function () {
window.location.pathname="/user";
}.bind(this),500);
}
}
else {
console.log("No support for local storage");
}}
What should I change to make it more secure? Or should I move to another solution, without using Local Storage at all?