Cookies in a client server page
Answered
Pacific herring posted this in #help-forum
Pacific herringOP
So I have this page rendered on the client side because I use react-hook-form, and it needs to have "use client".
Now when you log in, i create the cookie "logged". I have to check if the user has the "logged" cookie when they visit the signup page, and if they got it then I have to send them to the dashboard page, but I get the error that I cannot use next/headers in a client side page, which is right.
How could I do it? I was checking at serverActions that is experimental but still get the same errors.
Now when you log in, i create the cookie "logged". I have to check if the user has the "logged" cookie when they visit the signup page, and if they got it then I have to send them to the dashboard page, but I get the error that I cannot use next/headers in a client side page, which is right.
How could I do it? I was checking at serverActions that is experimental but still get the same errors.
7 Replies
Pacific herringOP
@DirtyCajunRice | AppDir @Sohel Shekh thank u. i have one last question.
const middleware = async (request: NextRequest) => {
if(request.url.includes('/signin/')) {
console.log("Middleware");
console.log(request.url)
}
}when the url is http://localhost:3000/signin, it matches and doeos the log in the consol. http://localhost:3000/ does the same as well though, and it returns the same result as if Im visiting /signup page.
If i visit /signup doesnt trigger anything as expected though.
http://localhost:3000/_next/static/chunks/app/signin/page.jsIf i visit /signup doesnt trigger anything as expected though.
Is it because when you visit http://localhost:3000 it "triggers" all the project's pages?
Pacific herringOP
nvm i think i fixed it.
Pacific herringOP
fixed but i have to open another thread
Answer