I have a root layout that has NavBar Component as below:
export default async function NavBar() {
const session = await getSession();
let account = null;
if (session) {
account = await prisma.account.findUnique({ where: { id: session.accountId } });
}
return (
// ...
and getSession()
function is defined as below:
export async function getSession() {
const session = cookies().get("rim_session")?.value;
if (!session) return null;
return await decrypt(session);
}
which basicaly just get a session cookie and decrypts it. (It's a JWT)
But the problem is, even though after its expiration, when I visit any page it doesn't get re-invoked since this is a server component that does not revalidate itself unless I explicitly refresh the browser.
How can I fix this problem? Maybe using some kind of a middleware?