I working on an app where I have to receive data from back which contains userdetail
object.
I want to assign a current accessToken to the userdetail object in my code:
useEffect(() => {
if (session?.user && pageLoad) {
try {
axios
.get(`${process.env.CONTENT_GHAR_API_URL}/auth/userDetail`, {
headers: {Authorization: session.user.data.accessToken},
})
.then(response => {
setPageLoad(false);
console.log("response", response);
if (response?.data) {
response.data?.message?.userDetail?.accessToken =session?.user?.data?.accessToken;
localStorage.setItem("uniqueId",response.data?.message?.userDetail?._id,);
dispatch(userDetail(response.data.message.userDetail));
}
});
} catch (error) {
setPageLoad(false);
}
}
}, [session]);
When I run the app, I ended up with the error Syntax error: Invalid left-hand side in assignment expression.* for the code shown above. Why? What is the correct way to update that value then?