We recently switched our Prismic repo to Private mode after generating the access token in the dashboard.
In our Prismic configuration, we are exporting our client as so:
import Prismic from 'prismic-javascript';
export const Router = {
routes: [
{ type: 'page', path: '/:uid' },
{ type: 'blog', path: '/blog/:uid' },
],
href: (type) => {
const route = Router.routes.find((r) => r.type === type);
return route && route.href;
},
};
export const Client = (_req = null, options = {}) => {
options = {
...options,
accessToken: accessToken,
};
return Prismic.client(apiEndpoint, { routes: Router.routes, ...options });
};
When created in this manner, we get the error
Error: Unexpected status code [401] on URL https://<REDACTED>.cdn.prismic.io/api/v2?access_token=<REDACTED>?routes=%5B%7B%22type%22%3A%22page%22%2C%22path%22%3A%22%2F%3Auid
%22%7D%2C%7B%22type%22%3A%22blog%22%2C%22path%22%3A%22%2Fblog%2F%3Auid%22%7D%5D
I noticed in the link above, the routes querystring parameter is preceded by the ? and not an &, so it has 2 ?'s in that querystring. Also, it appears the routes are double encoded.
If I remove the Routes from the client, the request works. Also, if I switch the ?routes to &routes and single encode the parameter, it also works:
https://<REDACTED>.cdn.prismic.io/api/v2?access_token=<REDACTED>&routes=[{"type"%3A"page"%2C"path"%3A"%2F%3Auid"}%2C{"type"%3A"blog"%2C"path"%3A"%2Fblog%2F%3Auid"}]
https://<REDACTED>.cdn.prismic.io/api/v2?access_token=<REDACTED>
Am I creating the client and Routes incorrectly?