Skip to content

Commit

Permalink
refactor(env): split sanity read tokens between server and client
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Jul 14, 2020
1 parent aca2403 commit e853ab1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ NEWSLETTER_SUBSCRIBERS_GROUP_ID='XXXXXXXXXXXXXXXXXXXXXX'
SLACK_WEBHOOK_URL='https://hooks.slack.com/services/xxxxxxxxxxxxxxxxx'
SITE_RECAPTCHA_SECRET=''
SANITY_WRITE_TOKEN=''
SANITY_READ_TOKEN=''

# public
NEXT_PUBLIC_CANONICAL_URL='https://example.com'
NEXT_PUBLIC_GA='UA-XXXXXXXXX-X'
NEXT_PUBLIC_IS_SUBMIT_FORM_ENABLED='true|false'
NEXT_PUBLIC_SANITY_PROJECT_ID='xxxxxxxx'
NEXT_PUBLIC_SANITY_READ_TOKEN=''
NEXT_PUBLIC_SANITY_READ_TOKEN_CLIENT_SIDE=''
NEXT_PUBLIC_SITE_RECAPTCHA_KEY='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import sanityClient from '@sanity/client';
const client = sanityClient({
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID || '',
dataset: 'production',
token: process.env.NEXT_PUBLIC_SANITY_READ_TOKEN || '',
token: process.env.NEXT_PUBLIC_SANITY_READ_TOKEN_CLIENT_SIDE || '',
// Always use the freshest data (as we're going to save it to disk)
useCdn: false,
ignoreBrowserTokenWarning: true,
});

export const getPostReviews = async (postId: string): Promise<{ reviews: number[] }> =>
Expand Down
2 changes: 1 addition & 1 deletion pages/[categoryId]/[postId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
usePostReviewsState,
usePostReviewsDispatch,
} from '../../components/blog-post/blog-post-reviews-context';
import { getPostReviews } from '../../components/blog-post/sanity-client';
import { getPostReviews } from '../../components/blog-post/sanity-browser-client';

import { joinUrl, postDateToHumanString } from '../../scripts/utils';

Expand Down
2 changes: 1 addition & 1 deletion sanity/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ sanityFetch(query).then((posts) => console.log(posts));
const client = sanityClient({
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
dataset: 'production',
token: process.env.NEXT_PUBLIC_SANITY_READ_TOKEN || '',
token: process.env.SANITY_READ_TOKEN || '',
// Always use the freshest data (as we're going to save it to disk)
useCdn: false,
});
Expand Down

0 comments on commit e853ab1

Please sign in to comment.