next build error cookies and location
Answered
Inca Dove posted this in #help-forum
Inca DoveOP
i got error while building my next js app like the picture
its the cookie error because of nextauth and need to set the cookie first?
and none of my code are using location, all of them using useRouter from next/navigation
how to fix this?
its the cookie error because of nextauth and need to set the cookie first?
and none of my code are using location, all of them using useRouter from next/navigation
how to fix this?
Answered by Ray
ok try change this
to
if (session?.role !== "ADMIN") {
router.push("/dashboard");
}to
useEffect(() => {
if (session?.role !== "ADMIN") {
router.push("/dashboard");
}
}, [session])9 Replies
@Inca Dove i got error while building my next js app like the picture
its the cookie error because of nextauth and need to set the cookie first?
and none of my code are using location, all of them using useRouter from next/navigation
how to fix this?
could you show the code on app/dashboard/ppdb/pengaturan/page?
Inca DoveOP
ok try change this
to
if (session?.role !== "ADMIN") {
router.push("/dashboard");
}to
useEffect(() => {
if (session?.role !== "ADMIN") {
router.push("/dashboard");
}
}, [session])Answer
Inca DoveOP
let me try
wow its works
so the problem is the cookie from the nextauth right?
but anyway, thanks a lot!
but anyway, thanks a lot!
it try to use
router.push() on the server because client component will still render on the server@Inca Dove so the problem is the cookie from the nextauth right?
but anyway, thanks a lot!
np, please mark solution if you problem has been solved