Token based authentication with Clerk
This guide will show you how to use Clerk as your authentication provider in an existing Next.js + WunderGraph application.
Configure Clerk
- 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 - Go to
JWT Templates
and create a newBlank
template - Name it
wundergraph
- Use the following template: (You can also include other claims as needed)
1
2
3
4
5
6
7
- Copy the JWKS Endpoint url
Configure WunderGraph
Open wundergraph.config.ts
and add a new token-based authentication provider:
1
2
3
4
5
6
7
8
9
10
11
Configure Next.js
Open pages/_app.tsx
and add the useWunderGraphClerk
middleware to the withWunderGraph
call:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
That's it! Your WunderGraph application is now protected by Clerk.