Next.js Quickstart
This tutorial adds Keyward sign-in to a new Next.js app using the App Router.
Before you start: you need a Keyward application. Create one in the dashboard — the free plan covers 10,000 monthly users.
- Install @keyward/nextjs
- npm
- pnpm
- yarn
npm install @keyward/nextjspnpm add @keyward/nextjsyarn add @keyward/nextjs - Set your keys
Add your publishable and secret keys to
.env.local. Never commit the secret key..env.local NEXT_PUBLIC_KEYWARD_PUBLISHABLE_KEY=pk_test_•••• KEYWARD_SECRET_KEY=sk_test_•••• - Add the proxy
proxy.ts import { keywardProxy } from "@keyward/nextjs/server"; export default keywardProxy(); export const config = { matcher: ["/((?!_next|.*\\..*).*)", "/(api|trpc)(.*)"], }; - Wrap your app
app/layout.tsx import { KeywardProvider, SignedIn, SignedOut, SignInButton, UserMenu } from "@keyward/nextjs"; export default function RootLayout({ children }: { children: React.ReactNode }) { return ( <KeywardProvider> <html lang="en"> <body> <header> <SignedOut><SignInButton /></SignedOut> <SignedIn><UserMenu /></SignedIn> </header> {children} </body> </html> </KeywardProvider> ); } - Run it
npm run devOpen
localhost:3000, select Sign in, and create the first user.
Next steps
Guide | What you will learn |
|---|---|
Require a session on a page or an API route | |
Use | |
Change colours, fonts and layout |
Updated
Was this page helpful?