Get up and running with @warpy-auth-sdk/core in 5 minutes.
This guide will help you set up authentication with Google OAuth in a Next.js 16 application using the new Proxy feature for Clerk-like ergonomics.
If you don't have a Next.js project yet, create one:
npx create-next-app@latest my-auth-app
cd my-auth-appnpm install @warpy-auth-sdk/coreCreate a .env.local file in your project root:
# Required: Your JWT signing secret (min 32 characters)
AUTH_SECRET=your-secret-key-min-32-chars-long-replace-this-in-production
# Google OAuth credentials (get from Google Cloud Console)
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
GOOGLE_REDIRECT_URI=http://localhost:3000/api/auth/callback/googleAUTH_SECRET to version control. Use a strong, random secret in production.Create a proxy.ts file in your app root (Next.js 16 feature):
This file handles all authentication routes automatically
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { authMiddleware } from "@warpy-auth-sdk/core/next";
import { google } from "@warpy-auth-sdk/core";
const handler = authMiddleware(
{
secret: process.env.AUTH_SECRET!,
provider: google({
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
redirectUri: process.env.GOOGLE_REDIRECT_URI!,
}),
callbacks: {
// Resolve/upsert your user with smallest overhead
async user(u) {
// return { id, email, name?, picture? } from your DB
return {
id: "1",
email: u.email,
name: u.name,
picture: u.picture
};
},
jwt: (t) => t,
session: (s) => s,
},
},
{
basePath: "/api/auth",
successRedirect: "/dashboard",
errorRedirect: "/login",
}
);
export function proxy(request: NextRequest) {
const p = request.nextUrl.pathname;
if (p.startsWith("/api/auth")) return handler(request);
return NextResponse.next();
}
export const config = {
matcher: [
"/((?!_next|[^?]*\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)",
"/(api|trpc)(.*)",
],
};Wrap your app with the AuthProvider:
Add the AuthProvider to your root layout
import { AuthProvider } from "@warpy-auth-sdk/core/hooks";
import "./globals.css";
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>
<AuthProvider>
{children}
</AuthProvider>
</body>
</html>
);
}Create a simple login page:
A simple login page with Google OAuth
'use client';
import { useAuth } from "@warpy-auth-sdk/core/hooks";
export default function LoginPage() {
const { session, loading } = useAuth();
if (loading) return <div>Loading...</div>;
if (session) return <div>Already signed in!</div>;
return (
<div className="min-h-screen flex items-center justify-center">
<div className="max-w-md w-full space-y-8">
<div>
<h2 className="mt-6 text-center text-3xl font-bold">
Sign in to your account
</h2>
</div>
<div>
<a
href="/api/auth/signin/google"
className="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-blue-600 hover:bg-blue-700"
>
Sign in with Google
</a>
</div>
</div>
</div>
);
}Create a dashboard that requires authentication:
A protected dashboard page
'use client';
import { useAuth } from "@warpy-auth-sdk/core/hooks";
export default function DashboardPage() {
const { session, loading, signOut } = useAuth();
if (loading) return <div>Loading...</div>;
if (!session) return <div>Please sign in</div>;
return (
<div className="min-h-screen p-8">
<div className="max-w-4xl mx-auto">
<div className="flex justify-between items-center mb-8">
<h1 className="text-3xl font-bold">Dashboard</h1>
<button
onClick={signOut}
className="px-4 py-2 bg-red-600 text-white rounded-md hover:bg-red-700"
>
Sign Out
</button>
</div>
<div className="bg-white p-6 rounded-lg shadow">
<h2 className="text-xl font-semibold mb-4">Welcome, {session.user.name}!</h2>
<p className="text-gray-600">Email: {session.user.email}</p>
{session.user.picture && (
<img
src={session.user.picture}
alt="Profile"
className="w-16 h-16 rounded-full mt-4"
/>
)}
</div>
</div>
</div>
);
}npm run devVisit http://localhost:3000/login to test your authentication flow!
Now that you have basic authentication working, you can:
Continue to the Environment Setup guide to configure your environment variables properly.