This example demonstrates how to configure caching based on authentication.
PREREQUISITES: You must set up a Sitefinity renderer application and connect it to your Sitefinity CMS application. For more information, see Install Sitefinity in Next.js mode.
middleware.ts
const hasAuthCookie = request.cookies.getAll().some(cookie => cookie.name.includes('AspNet.Cookies'));
Then, include this middlewareCache function into the app's middleware file. First, we check to ignore all requests that have already been processed by verifying the presence of the x-cached-route-processed header.
middlewareCache
x-cached-route-processed
if (request.headers.has('x-cached-route-processed')) { return NextResponse.next(); }
Then, add the new step from middlewareCache.
const resultCache = await middlewareCache(request); if (resultCache instanceof Response) { return resultCache; }
page.tsx
export const dynamic = 'force-static'; export const revalidate = 30
You can access the full middleware sample at the Sitefinity Next.js samples GitHub repository.
This sample is available in Sitefinity’s GitHub repository. You can run and play with it. To do this, perform the following:
\nextjs-samples-main\nextjs-samples-main\src \auth-cache
.env.development
PROXY SETTINGS
SF_CMS_URL
Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.
This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.
This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.
The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important