API Keys
Next.js
API Authentication in Next.js
Prerequisites
- Created your Unkey account
- Created an API in the Unkey dashboard
Skip the tutorial
We also have a Next.js example ready to deploy on Vercel.
1
Create Next.js Application
Run the following command to init your Next.js project
2
Install
Now install the @unkey/nextjs
package
3
Creating a protected route
Create a new route and add the following code
/app/protected/route.ts
4
Running it
5
Try it out
Go to https://app.unkey.com and create a new key. Then verify it with our new server:
It should return "Your API key is valid!"
and log out {"keyId":"key_id","valid":true,"meta":{},"enabled":true,"permissions":[],"code":"VALID"}
and potentially more information about the key, depending on what you set up in the dashboard.
What is next?
Now that you’ve seen the power of Unkey, check out some resources below to continue your journey.
Was this page helpful?