Forcing page with server components to reload each time?
Answered
Cape lion posted this in #help-forum
Cape lionOP
I have an app with simple login flow.
Users log in with username/password, and get redirected to a page (/app/stuff/page.tsx) that uses a session identifier in a cookie to load data from our DB.
The problem is that the page doesn't always render when a new user logs in.
So if I log in as user X, log out (validate that the cookie is cleared), log in as user Y... I get the page with user X's data. Not good.
I really need to check the session in the cookie and re-render the page on every single login.
How do I do this?
Users log in with username/password, and get redirected to a page (/app/stuff/page.tsx) that uses a session identifier in a cookie to load data from our DB.
The problem is that the page doesn't always render when a new user logs in.
So if I log in as user X, log out (validate that the cookie is cleared), log in as user Y... I get the page with user X's data. Not good.
I really need to check the session in the cookie and re-render the page on every single login.
How do I do this?
Answered by Cape lion
added all these to the page, and I think it works. But would love to know if there's a better / more correct way:
export const dynamic = 'force-dynamic'
export const dynamicParams = true
export const revalidate = 0
export const fetchCache = 'force-no-store'3 Replies
Cape lionOP
added all these to the page, and I think it works. But would love to know if there's a better / more correct way:
export const dynamic = 'force-dynamic'
export const dynamicParams = true
export const revalidate = 0
export const fetchCache = 'force-no-store'Answer
if you use
next/headers (for reading cookies), it would opt you into dynamic, so this is a valid way (the fetch cache disable is nessary if you are doing fetch reqs with the user's state)Cape lionOP
Thank you!