Closed Saini-Gaurav closed 6 months ago
Hey there! I just had a look in the provided repo and found the reason for the redirect behavior. It's because of the following useEffect in your Header.js:
useEffect(() => {
if (auth) {
const unsubscribe = onAuthStateChanged(auth, (user) => {
if (user) {
const { uid, email, displayName } = user;
dispatch(
addUser({
uid: uid,
email: email,
displayName: displayName,
})
);
setIsLoggedIn(true);
console.log("User is signed in, about to redirect");
router.push("/");
} else {
dispatch(removeUser());
setIsLoggedIn(false);
router.push("/Login");
}
});
return () => {
// Clean up the subscription when component unmounts
unsubscribe();
};
}
}, [auth]);
You might want to change this specific behavior in there. Hope this helped! 👍
Link to the code that reproduces this issue
https://github.com/Saini-Gaurav/E-Commerce
To Reproduce
Current vs. Expected behavior
I want to be on the same page or url on refereshing the browser instead redirecting to the homepage or "/" url
Provide environment information
Which area(s) are affected? (Select all that apply)
Not sure
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
No response