I have a specific page I want to make sure always gets rendered on the server (doesn't get cached).
By reading the docs I believe that export const dynamic = 'force-dynamic should do the trick.
So here is my page.tsx
"use client";
import { useAuth } from "@/app/providers/AuthProvider";
import { Button } from "@/components/Button";
export const dynamic = "force-dynamic";
export default function Home() {
const { logout, user } = useAuth();
return (
<div className="min-h-screen">
<h1>
Hello, <span>{user?.nickname}</span>
</h1>
<br />
<Button className="bg-purple-400" onClick={logout}>
Logout
</Button>
</div>
);
}
When I run npm run build though it says that my route will still be statically generated:
Route (app) Size First Load JS
┌ ○ / 3.16 kB 81.5 kB
The reason I want to avoid this btw is because this route requires auth and I want middleware to run to check for the user's permissions. The reason why middleware doesn't get to run is because AWS Cloudfront (CDN) has this cached as static content for the user so it just sends it before the middleware even runs