I am currently working on a medium scale app and am a month into learning React. I got to the part where I need to authenticate users. I have written some code and It is working, but I don't know is it secure enough. When my users login, they are assigned with a JWT token like this:

await axios.post(APIbase + '/login', {
          username: username, password: password
           const token = res.data.token;
           localStorage.setItem('token', token);
       }).catch(err => {

And then, when the user makes a request to a server it send the token by an auth header like this:

 const token = localStorage.getItem('token');
      const headers = { Authorization: `Bearer ${token}`};
      const detailResult= await axios.get(API.base + API.details, {

Is this safe enough? I heard that this is a not really a good practice, but I am not sure what exactly should I do.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.