Search code examples
reduxreact-redux

How to check status login and redirect to dashboard in Redux


I created two pages: <login> and <dashboard>. In login form I create userInput and passwordInput and button submit. When the user type and click into button submit. When app start ,how to check if user logined to app, it will redirect to <dashboard> and if user have not login to app, it will redirect to login? Thanks you for support


Solution

  • Check with your token in cookies or local storage with the following database users

    export default function route(){
    

    if a user exists in your DB then set validation true or either false

    let validation=localStorage.getItem("token");
    
    if(validation){
    
    return(<Dashboard/>)
    
    }
    else{
    return(<Login/>)
    }