A component sometimes re-renders and other times doesn't with the same exact code.
Unanswered
Spruce Grouse posted this in #help-forum
Spruce GrouseOP
I have a component which is basically some reactive links on my nav bar, if the user is signed in and a cookie token is stored it will render a certain UI and vice versa.
When a user logs in and is redirected to the next page, sometimes the nav bar updates to reflect that he is logged in, however if I try that again, with the same username and password (also different username and pass), it doesn't work....
I can't figure out what makes it render/stop rendering randomly.
this is how I get the token:
This is getToken():
This component is in the RootLayout file for the application.
When a user logs in and is redirected to the next page, sometimes the nav bar updates to reflect that he is logged in, however if I try that again, with the same username and password (also different username and pass), it doesn't work....
I can't figure out what makes it render/stop rendering randomly.
this is how I get the token:
const token = await getToken();This is getToken():
"use server";
import { cookies } from "next/headers";
export async function getToken() {
return cookies().get("token");
}This component is in the RootLayout file for the application.
<Component />6 Replies
are you gonna get cookie in the client component using your
getToken()?Spruce GrouseOP
I just found out that when I route to a not found page the component always renders correctly. Also just to add more information, this also occurs in logout, however it's consistent with not working so at least there is some consistency here.
In the question I'd like to get two things done.
1. Have the component working for both login and logout.
2. Figure out the reason for inconsistency in the login flow.
In the question I'd like to get two things done.
1. Have the component working for both login and logout.
2. Figure out the reason for inconsistency in the login flow.
@James4u are you gonna get cookie in the client component using your `getToken()`?
Spruce GrouseOP
It's a server component right now but yes I'm using it in the reactive link component which I shared in the question as
<Component />I tried making it a client component just to test it but that didn't work
in the server component you can directly get cookies
Spruce GrouseOP
Yes I was doing that, I just didn't revert to back to it 😅