Quickstart
The Pylo Auth SDK (@pylo/auth-nextjs) handles user authentication for Next.js applications —
login, logout, session management, and automatic token refresh.
Install
$
pnpm add @pylo/auth-nextjsEnvironment
.env.local
1
PYLO_API_KEY=your-api-token-hereCreate an API token in Settings > API Tokens in your Pylo admin panel. See API Tokens for details.
Middleware Setup
Create a proxy.ts in your project root to handle authentication and automatic token refresh:
proxy.ts
1
2
3
4
5
6
7
8
9
10
11
12
import { createPyloProxy } from "@pylo/auth-nextjs";
export const proxy = createPyloProxy({
publicPaths: ["/auth"],
});
export const config = {
matcher: [
"/((?!_next/static|_next/image|favicon.ico|.*\..*|$).*)",
"/",
],
}This protects all routes by default and redirects unauthenticated users to /auth/login. Tokens are
refreshed automatically before they expire.
Need advanced middleware?
For custom redirect logic, route protection, or maintenance mode, see the Authentication guide.
Next Steps
- Set up Login & Logout for your users
- Add the Next.js SDK for type-safe data fetching
- Explore Server Utilities for auth checks in Server Components