help managing next js caching
Unanswered
Common Moorhen posted this in #help-forum
Common MoorhenOP
I fetch the user data on the server with cookies and show it with React. the problem is that when i sign out and log in again with a new account, the request is cached, so the UI stays identical until I refresh the page again.
is there a way to manage to revalidate some url when I want?
is there a way to manage to revalidate some url when I want?
4 Replies
Rough harvester ant
Use tag based cache when you fetch the user data and invalidate the tag when you logout.
Example:
const res = await fetch('https://...', { next: { tags: ['userdata'] } });
and the logout should be a server action
'use server'
import { revalidateTag } from 'next/cache'
export default async function logout() {
// do the logout logicc
revalidateTag('userdata')
}
Example:
const res = await fetch('https://...', { next: { tags: ['userdata'] } });
and the logout should be a server action
'use server'
import { revalidateTag } from 'next/cache'
export default async function logout() {
// do the logout logicc
revalidateTag('userdata')
}
Common MoorhenOP
aah okay
i will try it
ty