Quickstart
Next.js (app router)
Integrate CakeAuth into your Next.js app in just a few steps!
Before continuing
Make sure you have:
- Setup your account
- Next.js app configured
Install the package
Currently, we only support Next.js 13 and above with the app router. Older verisons of Next.js or using pages router still not supported.
Setup environment variables
In your .env.local
file (create one if it doesn't exist), add the following:
NEXT_PUBLIC_CAKEAUTH_PUBLIC_KEY
: your public keyCAKEAUTH_PRIVATE_KEY
: your private key
Don't know where to get those? Check out this quick cheat sheet.
Add CakeAuth middleware
Add CakeAuth middleware to your Next.js app:
In your src/middleware.ts
file, add the following:
Add ready-to-use components
Add CakeAuth middleware to your Next.js app:
- Add
CakeAuthProvider
to your layout file
- Add authentication components to your page
What's next?
TODO:
- Add more auth options
- protect pages/components
- protect API routes
- session management
- more on sdk reference
Last updated on