You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
most of the example code looks something like this:
productionUrl: async (prev, context) => {
const { getClient, dataset, document } = context;
const client = getClient({ apiVersion: '2022-06-07' }); // Ensure to specify the correct API version
const slug = await client.fetch(`*[_id == $id][0].slug.current`, { id: document._id });
// Define your base production URL
const baseUrl = 'https://your-production-site.com';
// Build the URL based on the document type
let url;
switch (document._type) {
case 'page':
url = `${baseUrl}/${slug}/`;
break;
case 'post':
url = `${baseUrl}/posts/${slug}`;
break;
default:
url = baseUrl;
}
// Optionally add any query parameters
return `${url}?preview=true`; // <------------- see this line in particular
}
This uses a query string to enable the preview mode, instead of first browsing to /preview/enable. Is this possible at the moment? To enable the preview mode by passing a query string?
EDIT 1:
I tried the following: created a sanity.client.js file in the plugins, but the previews mode is not enabled so it seems
The only issue now, is that we need to find a way to add the secret to this link, the token is stored in the web .env, should it be stored in the studio .env as well, and passed here?
Thanks!
The text was updated successfully, but these errors were encountered:
I'm trying to get the "Open Preview" button functionality working, see: https://www.sanity.io/docs/migrating-production-url-resolver
most of the example code looks something like this:
This uses a query string to enable the preview mode, instead of first browsing to /preview/enable.
Is this possible at the moment? To enable the preview mode by passing a query string?
EDIT 1:
I tried the following: created a
sanity.client.js
file in the plugins, but the previews mode is not enabled so it seemsEDIT 2:
I saw in the code that there's a redirectTo variable, so that we can use the default /preview/enable.
The only issue now, is that we need to find a way to add the secret to this link, the token is stored in the web .env, should it be stored in the studio .env as well, and passed here?
Thanks!
The text was updated successfully, but these errors were encountered: