-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsanity.js
30 lines (20 loc) · 913 Bytes
/
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
import {
createCurrentUserHook,
createClient,
} from 'next-sanity';
import createImageUrlBuilder from '@sanity/image-url';
export const config = {
//
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET || 'production',
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
apiVersion: '2022-03-10',
// set useCdn to 'false' if your application require the freshest possible data always,
// authenticated request will always bypass the CDN
useCdn: process.env.NODE_ENV === 'production',
}
// setup the clint for fetching the data in the getProps page functions
export const sanityClient = createClient(config)
// for generating the imageUrl with only the asset reference data in document
export const urlFor = (source) => createImageUrlBuilder(config).image(source)
// helper function for using the current logged in user account
export const useCurrentUser = createCurrentUserHook(config)