I need to hide some content on the public API routes, based on the current session.
export const revalidate = 0;
export const dynamic = "force-dynamic";
export const fetchCache = "force-no-store";
export async function GET(request: Request) {
const session = await getServerSession(config);
// Example list
const types = ['item1', 'item2', ....];
return Response.json(
{
// Data from an external API
data: data.map((item) => {
if (!session) {
types.forEach((key: string) => {
if (item[key]) {
item[key] = null;
}
});
}
return item;
}),
},
{
status: 200,
},
);
});
I’m currently using this route.ts
, the problem is that when accessing the static generated sites, and it called the URL once, its seem to cache it, and then when logging in, and therefore creating an active session, the route doesn’t update, and still remembers the API data from the call once no session were available.
Anyone know how to fix?
I’m thinking og just creating multiple routes, one for logged in sessions, and one for non-active sessions, but just alot of duplicate work….
madsenmm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.