Created
July 18, 2021 18:36
-
-
Save j2is/dcc01c4a087fb02d70fa18120dd9e43d to your computer and use it in GitHub Desktop.
Next Sanity Server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// lib/sanity.server.js | |
import { createClient } from "next-sanity"; | |
import { config } from "./config"; | |
// Set up the client for fetching data in the getProps page functions | |
export const sanityClient = createClient(config); | |
// Set up a preview client with serverless authentication for drafts | |
export const previewClient = createClient({ | |
...config, | |
useCdn: false, | |
token: process.env.SANITY_API_TOKEN, | |
}); | |
// Helper function for easily switching between normal client and preview client | |
export const getClient = (usePreview) => (usePreview ? previewClient : sanityClient); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment