Configuration
This page covers all the configuration options for the Headless Shopify project.
Environment Variables
The following environment variables are required to run the application:
Required Variables
NEXT_PUBLIC_SHOPIFY_STOREFRONT_GRAPHQL_ENDPOINT
Your Shopify Storefront GraphQL API endpoint.
Format:
https://your-store.myshopify.com/api/2024-01/graphql.json
How to get it:
- Go to your Shopify Admin
- Navigate to Settings → Apps and sales channels
- Create a custom app or use an existing one
- Copy the Storefront API endpoint
NEXT_PUBLIC_SHOPIFY_STOREFRONT_ACCESS_TOKEN
Your Shopify Storefront API access token.
How to get it:
- In your Shopify Admin, go to the custom app
- Navigate to API credentials
- Copy the Storefront API access token
BETTER_AUTH_SECRET
Secret key for Better-Auth authentication library.
How to generate:
openssl rand -base64 32
This secret is used to sign and verify authentication tokens. Keep it secure and never commit it to version control.
SHOPIFY_MULTIPASS_SECRET
Shopify Multipass secret for social login integration (requires Shopify Plus).
How to get it:
- Log in to your Shopify Admin
- Navigate to Settings → Customer accounts
- Enable Multipass (available only on Shopify Plus plans)
- Copy the Multipass secret key
Note: Multipass is only available on Shopify Plus plans. If you're on a lower plan, social login integration won't be available.
GOOGLE_CLIENT_ID (Optional)
Google OAuth Client ID for Google social login.
How to get it:
- Go to Google Cloud Console
- Create a new project or select an existing one
- Navigate to APIs & Services → Credentials
- Click Create Credentials → OAuth client ID
- Configure the OAuth consent screen
- Set application type to Web application
- Add authorized redirect URIs:
http://localhost:3000/api/auth/callback/google(development)https://yourdomain.com/api/auth/callback/google(production)
- Copy the Client ID
GOOGLE_CLIENT_SECRET (Optional)
Google OAuth Client Secret that pairs with the Client ID.
Security: Keep this secret secure and never commit it to version control.
Example .env File
# Shopify Storefront API Configuration
NEXT_PUBLIC_SHOPIFY_STOREFRONT_GRAPHQL_ENDPOINT=https://your-store.myshopify.com/api/2024-01/graphql.json
NEXT_PUBLIC_SHOPIFY_STOREFRONT_ACCESS_TOKEN=your_access_token_here
# Better-Auth Configuration
BETTER_AUTH_SECRET=your_generated_secret_here
# Shopify Multipass (Shopify Plus only)
SHOPIFY_MULTIPASS_SECRET=your_multipass_secret_here
# Google OAuth (Optional - for social login)
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
Shopify Setup
To use this project, you need a Shopify store with the Storefront API enabled. There are two ways to set this up:
Option 1: Using the Headless App (Recommended)
The easiest way to get started is by using the official Headless app from Shopify.
-
Log in to your Shopify Admin
-
Go to Settings → Apps and sales channels
-
Click Shopify App Store
-
Search for "Headless" (official Shopify app)
-
Click Install and follow the prompts
-
Once installed, the Headless app will automatically:
- Generate a Storefront API access token
- Configure the required API scopes
- Provide you with the API credentials
-
Copy the credentials from the Headless app dashboard:
- Storefront API endpoint
- Storefront API access token
Benefits of using the Headless app:
- Quick and easy setup
- Automatic scope configuration
- Official Shopify support
- Purpose-built for headless storefronts
Option 2: Creating a Custom App
Alternatively, you can create a custom app manually:
- Log in to your Shopify Admin
- Go to Settings → Apps and sales channels
- Click Develop apps
- Click Create an app
- Name your app (e.g., "Headless Storefront")
- Click Create app
Configuring API Access (Custom App)
- In your custom app, go to Configuration
- Under Storefront API, click Configure
- Enable the required access scopes:
- Read products
- Read customers
- Read orders
- Write cart
- Read cart
- Save your changes
- Go to API credentials and copy your access token
Authentication Configuration
The project uses Better-Auth for authentication with a custom Shopify plugin.
Authentication Features
- Email/Password authentication via Shopify Customer API
- Google Social Login via OAuth 2.0 and Shopify Multipass
- Forgot password and Reset password flows
- Customer account management
- Secure cookie-based sessions
Better-Auth Setup
Better-Auth is configured in src/lib/auth.ts with:
- Next.js cookies plugin for secure session management
- Custom Shopify plugin that integrates with Shopify's Customer API
- Social providers (Google OAuth)
Google Social Login Setup
To enable Google social login:
- Set up a Google Cloud project and OAuth credentials (see
GOOGLE_CLIENT_IDabove) - Enable Multipass in your Shopify admin (Shopify Plus required)
- Add the required environment variables
- The integration automatically:
- Authenticates users via Google OAuth
- Creates/signs in Shopify customers via Multipass
- Stores access tokens in secure HTTP-only cookies
Note: Google social login requires a Shopify Plus account for Multipass functionality.
Important Notes
- Never commit your
.envfile to version control - Keep your Storefront API access token secure
- Rotate your tokens regularly for security
- Use different credentials for development and production
Next Steps
- Learn about the Project Structure
- Deploy your app with the Deployment Guide