'Storing JWT on local storage shows undefined in React Project
I have found difficulties while storing JWT on my local browser. Here is my code:
const SignIn = () => {
const navigate = useNavigate();
let location = useLocation();
const from = location.state?.from?.pathname || '/';
const [
signInWithEmailAndPassword,
user,
loading,
error,
] = useSignInWithEmailAndPassword(auth, {sendEmailVerification:true});
const handleUserSignIn = async event =>{
event.preventDefault();
const email = event.target.email.value;
const password =event.target.password.value;
await signInWithEmailAndPassword(email, password);
const {data} =await axios.post("http://localhost:5000/signin", {email});
localStorage.setItem('accessToken', data.accessToken)
navigate (from, {replace: true});
}
}
I get the key property key name okay but the value shows "undefined" accessToken undefined
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
