Documentation
Quickstart โ 5 minutes to production auth
Add Kynetra Auth to a Next.js app in 5 minutes. By the end you'll have sign-up, sign-in, and a protected route.
1
Install the SDK
bash
npm install @kynetra/nextjs
2
Set environment variables
Copy from your dashboard โ Settings โ API Keys.
bash
KYNETRA_PUBLISHABLE_KEY=pk_live_... KYNETRA_SECRET_KEY=sk_live_... KYNETRA_APP_URL=https://yourdomain.com
3
Add the provider to your root layout
tsx
// app/layout.tsx
import { KynetraProvider } from '@kynetra/nextjs';
export default function RootLayout({ children }) {
return (
<html>
<body>
<KynetraProvider>
{children}
</KynetraProvider>
</body>
</html>
);
}4
Add the auth middleware
tsx
// middleware.ts
import { authMiddleware } from '@kynetra/nextjs';
export default authMiddleware({
publicRoutes: ['/', '/marketing(.*)'],
});
export const config = {
matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
};5
Protect a page and read the user
tsx
// app/dashboard/page.tsx
import { currentUser } from '@kynetra/nextjs/server';
import { redirect } from 'next/navigation';
export default async function DashboardPage() {
const user = await currentUser();
if (!user) redirect('/auth/signin');
return <h1>Hello, {user.firstName}!</h1>;
}That's it!
Run npm run dev and visit /dashboard โ you'll be redirected to the Kynetra sign-in page automatically.