Setting Up Post and Page Previews
Faust.js has support for page and post previews. This allows you to view your WordPress content on the headless frontend as drafts or even before publishing.
Set Your Headless Secret#
Your headless secret is a value that is used to authenticate requests to WordPress. This enables you to view content that isn't yet published, on your Next.js frontend.
Copy your Headless Secret#
Your headless secret can be found in WP Admin -> Settings -> Headless. Copy this value.

Add your Headless Secret to your .env File#
Add the WP_HEADLESS_SECRET key to your .env file with the headless secret as the value. Your .env file should already have a value for either NEXT_PUBLIC_WORDPRESS_URL or WORDPRESS_URL. The file should look something like this:
Ensure your Headless Secret is Passed to headlessConfig#
Typically, your Next.js app will have headlessConfig set in the _app.tsx file. The headless secret is passed via the apiClientSecret key. Make sure it is being set:
Create the Authorize Handler#
Next, you will need to create the authorizeHandler. This authenticates requests from WordPress. Create a page at /src/pages/api/auth/wpe-headless.ts with the following:
Create your Preview Page#
With your headless secret set and the authorizeHandler ready to handle requests, you can now create a Next.js page for previews. Create a file at /src/pages/preview.tsx with the following:
Let's break down what is going on here:
First we are getting the p and page_id values from the Next.js Router query:
We then use these values in our usePreview hook to fetch the correct post or page:
Finally, based on whether isPage is true, we will return a <PageComponent /> or <PostComponent /> respectively.
We abstract the page and post layouts into components to be reusable so there is no divergence between preview pages/posts and actual pages/posts.
Navigating to Preview Pages#
Start by logging into your WordPress Admin. For this example, we'll create a new post.
So far, I've added a title and a simple line of text for the content. To view this post as a preview on your frontend, click the Preview link (1). From there, click, Preview in new tab (2):

Notice the Publish button is also visible. This means the post has not been published yet and can not be viewed on the frontend without being authenticated.
Clicking on Preview in new tab should take you to your post preview page with the current preview content:
