-
Notifications
You must be signed in to change notification settings - Fork 0
/
sanity.js
36 lines (33 loc) · 1.33 KB
/
sanity.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import {
createClient,
createCurrentUserHook,
} from "next-sanity";
import imageUrlBuilder from '@sanity/image-url'
export const config = {
/*
Find your projectID and dataset in `sanity.json` in your studio project.
these are considered "public", but you can use environment variables
if you want differ between local dev and production
https://nestjs.org/docs/basic-features/environment-variables
*/
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET || "production",
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
apiVersion: "2021-03-25",
/*
Set useCdn to `false` if your application require the freshest possible
data always (potentially slightly slower and a bit more expensive).
Authenticesed request (like preview) will always bypass the CDN.
*/
useCdn: process.env.NODE_ENV === "production",
}
// set up the client for fetching data in the getProps page function
export const sanityClient = createClient(config);
/*
Set up a helper function for generating Image URLs with only the asset
reference dta in your documents.
Red more: https://www.sanity.io/docs/image-url
*/
const builder = imageUrlBuilder(sanityClient)
export const urlFor = (source) => builder.image(source);
// helper function for using the current logged in user account
export const useCurrentUser = createCurrentUserHook(config);