Router.push() works, but manually inputing URL doesn't.
Unanswered
Texas leafcutting ant posted this in #help-forum
Texas leafcutting antOP
Hi there, my team is developing a application in next.js using material-ui and tailwind (we are NOT using material-ui specific for tailwind, because it's a paid lib) and we are having some problems with the redirecting of a page after we log an user in. We are using Router to do this redirect to the main page after a token is received from the api, but if we manually input the /login URL in our browsers we end up with a loss of stylezation on some components, such as material-ui button one. Is this a known issue or are there any better ways to do it? I'll past the code below.
``
const [userEmail, setUserEmail] = useState("");
const [userPassword, setUserPassword] = useState("");
const access_token = getStoredValue("access_token");
const router = useRouter();
const handleEmailChange = (e) => {
setUserEmail(e.target.value);
console.log(e.target.value);
};
const handlePasswordChange = (e) => {
setUserPassword(e.target.value);
};
const userLogin = async (event, email, password) => {
event.preventDefault();
if (!access_token) {
mecredApi
.post("/auth/sign_in", {
email: userEmail,
password: userPassword,
})
.then(response => {
saveToLocalStorage("user_data", JSON.stringify(response.data["data"]));
saveToLocalStorage("access_token", response.headers["access-token"]);
router.push("/");
})
.catch((error) => console.log(error.response));
}
};
}
```
Any suggestion are welcome! Also, we are using several OS's to develop the app, Ubuntu 20, 22, Arch and Mint.
``
const [userEmail, setUserEmail] = useState("");
const [userPassword, setUserPassword] = useState("");
const access_token = getStoredValue("access_token");
const router = useRouter();
const handleEmailChange = (e) => {
setUserEmail(e.target.value);
console.log(e.target.value);
};
const handlePasswordChange = (e) => {
setUserPassword(e.target.value);
};
const userLogin = async (event, email, password) => {
event.preventDefault();
if (!access_token) {
mecredApi
.post("/auth/sign_in", {
email: userEmail,
password: userPassword,
})
.then(response => {
saveToLocalStorage("user_data", JSON.stringify(response.data["data"]));
saveToLocalStorage("access_token", response.headers["access-token"]);
router.push("/");
})
.catch((error) => console.log(error.response));
}
};
}
```
Any suggestion are welcome! Also, we are using several OS's to develop the app, Ubuntu 20, 22, Arch and Mint.