I have a profile screen it renders based on cookies. When cookie is not present or invalid, it renders a login link. Then when the user logs in and comes back to the profile page, it also renders login link until user refreshes the page.
My understanding tells me that browser is caching the page.
So how can I disable this page from being cached in browser?
This is my code
👇👇👇👇👇👇👇👇👇
import Link from 'next/link';
import { cookies } from 'next/headers';
import getTokenData from '@/helper/token';
const ProfilePage = ({ params }) => {
const incomingToken = cookies()?.get('token')?.value;
const tokenDecode = getTokenData(incomingToken);
if (tokenDecode.success && tokenDecode?.data?.isAdmin) {
return (
<Frame>
// some component
</Frame>
);
}
if (tokenDecode.success) {
return (
<Frame>
// some component
</Frame>
);
}
return (
<Frame>
// some component
</Frame>
);
};
2
Answers
If the problem is solved when refreshing the page maybe you can just use location.reload() (javascript) to refresh the page after login. I don’t know if that’s useful for you.
On your
const tokenDecode = getTokenData(incomingToken);
api call if you are using fetch you can disable cache by adding{ cache: 'no-store' }
after urlRef: Opt out cache in next 13 app router