#Lesson 8.2 - Connect the storefront
In this lesson, you will configure Content API access in Hygraph and add two environment variables to the starter. By the end, the storefront is running locally and displaying published content.
#Two access modes
Before configuring anything, it helps to understand why there are two separate configurations.
Hygraph exposes a single Content API endpoint. The starter uses two different ways to access content through that endpoint:
- The Content API serves the storefront for public visitors. It only returns content in the
PUBLISHEDstage. No authentication is required. - A Permanent Auth Token (PAT) grants the frontend access to
DRAFTcontent. It is used only for the preview URL configured in lesson 8.3.
#Configure Content API permissions
The Public Content API needs read permissions initialized before unauthenticated requests can return content.
-
Navigate to Project settings > Access > Content API.
-
In the Content Permissions box, click Initialize defaults.
The content permissions box now looks like this:
Content permissions initialized -
Navigate to Project settings > Access > Endpoints. Copy the High Performance Content API endpoint URL from this screen. You will need it while adding environment variables.
For a full reference on public API permissions, see Public API permissions.
#Create a PAT for draft content
- Navigate to Project settings > Access > Permanent Auth Tokens.
- Click + Add token.
- Enter a name and optional description, select DRAFT as the default stage for content delivery, and click Add & configure permissions.
- On the token details screen, copy the token value. You will need it while adding environment variables.
For a full reference on Permanent Auth Tokens, see Authorization.
#Add environment variables
Copy the .env.sample file and rename it to .env.local:
cp .env.sample .env.local
Open .env.local and add the two values collected above:
HYGRAPH_ENDPOINT=YOUR_CONTENT_API_ENDPOINT_HEREHYGRAPH_DEV_AUTH_TOKEN=YOUR_DRAFT_TOKEN_HEREHYGRAPH_PREVIEW_SECRET=
Leave HYGRAPH_PREVIEW_SECRET empty for now. You will configure it in the next lesson.
#Run the storefront
Start the local development server:
npm run dev
Open http://localhost:3000 in your browser. The storefront should display your published content.
Starter homepage
Product page
The Content API only returns content in the PUBLISHED stage. If the storefront is blank, open the content editor and verify that all content entries created in lesson 6.1 are published.
The storefront renders your landing pages, product pages, navigation, and review data using the same GraphQL queries practiced in lesson 7.1. The utils/ directory in the starter contains the query functions. Spend some time exploring the code in your editor to understand how the Hygraph content maps to the frontend components.
#What's next
Lesson 8.3 - Configure a preview URLOr, go to the Tutorial overview for the full lesson list.