Next.js + Clerk Example
The NextJS + Clerk example demonstrates how you can use Clerk as your authentication provider with WunderGraph.
This example uses Clerk JWT Templates, Clerk Next.js integration and the WunderGraph Next.js client.
Installation
The quickest way to get started is by using create-wundergraph-app.
Configuration
Clerk API keys
First, you need to create a Clerk application and configure the Clerk API keys in your .env.local
file.
- Go to Clerk and create a new application or use an existing one.
- On your application dashboard to to
API Key
- Use the
Quick Copy
for Next.js and copy the.env.local
- Create a new
.env.local
file in the root folder (next to thepackage.json
) - Paste the credentials into the
.env.local
file
Clerk JWT Templates
- Go to
JWT Templates
and create a newBlank
template - Name it
wundergraph
- Use the following template: (You can also include other claims as needed)
- Copy the JWKS Endpoint url
- Add a new environment variable to
.env.local
calledCLERK_JWKS_URL
and paste the url as the value
Run the app
Running npm start
will start WunderGraph and Next.js in development mode.
Head over to http://localhost:3000
in your browser to see the integration in action.
Clicking the Login
button will redirect you to the Clerk login page. After logging in, you will be redirected back to the app and you will see the result of the Countries operation and the user claims.
Learn more
Deploy to WunderGraph Cloud
The easiest way to deploy your WunderGraph app is to use WunderGraph Cloud. Enable the Vercel integration to deploy the Next.js frontend to Vercel.