I'm trying to preview an unpublished page but am just getting a 404 page. I've tried adding my customTypesApiToken
to the gatsby-plugin-prismic-previews
within gatsby-config.js
, but I get the error Warning: there are unknown plugin options for "gatsby-plugin-prismic-previews": customTypesApiToken
. Everything else looks correct, and published previews are working just fine. Relevant files are below, but let me know if I can provide anything else.
gatsby-browser.js & gatsby-ssr.js
import * as React from 'react';
import {
PrismicPreviewProvider,
componentResolverFromMap,
} from 'gatsby-plugin-prismic-previews';
import { linkResolver } from './src/utilities/link-resolver';
import PageTemplate from './src/pages';
export const wrapRootElement = ({ element }) => (
<PrismicPreviewProvider
repositoryConfigs={[
{
repositoryName: process.env.GATSBY_PRISMIC_REPO_NAME,
linkResolver,
componentResolver: componentResolverFromMap({
page: PageTemplate,
}),
},
]}
>
{element}
</PrismicPreviewProvider>
);
404.js
import * as React from 'react';
import { withPrismicUnpublishedPreview } from 'gatsby-plugin-prismic-previews';
import Seo from '../components/Seo';
const NotFoundPage = ({ data }) => (
<>
<h1>404: Not Found</h1>
<p>You just hit a route that doesn't exist... the sadness.</p>
</>
);
export const Head = () => <Seo title="404: Not Found" />;
export default withPrismicUnpublishedPreview(NotFoundPage);
gatsby-config.js
require('dotenv').config({
path: `.env`,
});
const routes = [
{
type: 'homepage',
path: '/',
},
{
type: 'stories',
path: '/:uid',
},
{
type: 'jobs',
path: '/:uid',
},
{
type: 'story',
path: '/stories/:uid',
},
{
type: 'basic_page',
path: '/:uid',
},
];
module.exports = {
plugins: [
`gatsby-plugin-image`,
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `${__dirname}/src/images`,
},
},
{
resolve: 'gatsby-source-prismic',
options: {
repositoryName: process.env.GATSBY_PRISMIC_REPO_NAME,
accessToken: process.env.PRISMIC_ACCESS_TOKEN,
customTypesApiToken: process.env.PRISMIC_CUSTOM_TYPES_API_TOKEN,
routes,
linkResolver: require('./src/utilities/link-resolver').linkResolver,
},
},
{
resolve: 'gatsby-plugin-prismic-previews',
options: {
repositoryName: process.env.GATSBY_PRISMIC_REPO_NAME,
accessToken: process.env.PRISMIC_ACCESS_TOKEN,
routes,
},
},
{
resolve: `gatsby-plugin-layout`,
options: {
component: require.resolve(`./src/components/Layout.js`),
},
},
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
`gatsby-plugin-styled-components`,
{
resolve: `gatsby-plugin-manifest`,
options: {
name: `bay-city-website`,
short_name: `bay-city`,
start_url: `/`,
background_color: `#F6F5ED`,
theme_color: `#F6F5ED`,
theme_color_in_head: false,
display: `minimal-ui`,
icon: `src/images/gatsby-icon.png`,
},
},
],
};
link-resolver.js
exports.linkResolver = doc => {
// URL for a story type
if (doc.type === 'story') {
return `/stories/${doc.uid}`;
}
// URL for top-level page types
if (
doc.type === 'basic_page' ||
doc.type === 'stories' ||
doc.type === 'jobs'
) {
return `/${doc.uid}`;
}
// Backup for all other types
return '/';
};