I am making an axios post request to my server to log a user in and logging the response in the console to observe the data being returned:
const Login = () => {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const submitForm = (e) => {
e.preventDefault();
axios
.post("http://127.0.0.1:3000/login", { email, password })
.then((res) => console.log("res", res))
.catch((err) => console.log("err", err));
console.log({ email, password });
};
I generate a token when the user successfully logs in, returning the user's data alongside this newly generated token. As you can see here, I am deleting the user password from the response body in order to not expose the password:
const generateToken = (user) => {
delete user.password;
const token = jwt.sign(user, config.appKey, { expiresIn: 86400 });
return { ...user, ...{ token } };
};
Here is the logged data in the console. In image no.1, you can see there is no password in the data portion of the response.
However, in the config portion of the response, the password is exposed (see Image no.2). My question is, is this something to be concerned about? If so, how do I remove the user's password from the response altogether?
Thanks in advance!
If your connection is secure (HTTP over TLS, ...), it is not something you need to be concerned about.
The HTTP response does not include it, since the actual response payload is res.data.
It is stored in the axios response object, since res.config is the config that was provided to axios for the request. But it is not stored in any persistent storage.