The Problem of token Authentication

  node.js, question

Using react-router to make a Single-page application, the client authentication is realized by storing the token from the server through localstorage. When login component logs in successfully, LOCAL STORAGE. TOKEN = RES. BODY. TOKEN is set, but the problem is that if the same browser logs in to different accounts at the same time. The token of the first account will be overwritten by the token of the second account, so that the first account can request the data of the second account … I know that the name of the token is duplicated, but I have not introduced redux, so how can I notify my auth.js if the token of each user is given a different name?

This is my auth.js, and every function it exposes serves as an authentication hook for the routing component onEnter.

module.exports={

    /*token为空!请登录!*/
    redirectToLogin(nextState, replaceState){
        alert(localStorage.token);
        if(!localStorage.token || localStorage.token==""){
            alert(" 请登录! ");
            replaceState(null, '/marriage_app/login');
        }else{
            return;
        };
    },

    /*token不为空!已经登录过啦!*/
    redirectToApp(nextState, replaceState){
        if(localStorage.token && localStorage.token!=""){
            replaceState(null, '/marriage_app');
        }else{
            return;
        };
    },

    /*注销!清空 token!*/
    logout(nextState, replaceState){
        alert("logout");
        delete localStorage.token;
        replaceState(null, '/marriage_app/login');
    }
}

There is a problem here. First of all, the login of the client should be unique. If only the token is used to let the browser judge the login status, then if a user logs in successfully, then it means that all other users who log in to the machine or browser should be logged out. Otherwise, when two users log in at the same time, which user’s data do you want to request?