Next.js Discord

Discord Forum

Server Action & Cookies

Unanswered
West African Lion posted this in #help-forum
Open in Discord
West African LionOP
I have a question in a server action I set a cookie. After succesfully setting the cookie I redirect the user back to / where we check for a cookie if the user is logged in. Only this seems not to work. I already revalidate the path. Someone has any idea how this comes?

5 Replies

what is the route that called your server action?
and what is the result of your server action?
West African LionOP
Hey! 🙂 I called the server action using a form action. My server action has a async API call (which succeed) and then set the cookie. After that I revalidatePath and redirect the user back to the main layout.tsx where I try to access the cookie using const isloggedIn = cookies().has('session');. At this part it fails and has still the old value and not the new setted value.
what is the route that called your server action?
West African LionOP
I am calling it using a useTransition which is started by the onSubmit of the form. The route it is called from is @auth/login-as-guest/page.tsx and I try to redirect back to layout.tsx where I read the cookie