'How to use localStorage variable in safe?
Iam tray to use isAuthenticated useState in all component to stop users traying to set url of any other component but I think it is not safe to storage localStorage.getItem('user'); in localStorage how to fix or is there any other way to do this ?
const [isAuthenticated, userHasAuthenticated] = useState(localStorage.getItem('user') ||'false');
useEffect(() => {
var x =localStorage.getItem('user');
if (x=='false'){
window.location.assign("/");
}else{
console.log("ok");
}
}, []);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|