Quickstart
From nothing to working sign-up, sign-in, email verification and password reset. Steps 1 and 2 are the same everywhere; step 3 depends on your stack; everything after it is identical again.
Step 1
Create an app and copy the key
Create an account, confirm your email from the link we send you, and then create an app. For App URL, enter the origin your app runs on, such as https://myapp.com — every verification and reset email links back to it. Trying it on your machine first? Use http://localhost:3000, or whichever port your app runs on, and create a second app for production later. The next screen shows your secret key once, with the two variables below already filled in. It cannot be shown again; if you lose it, rotate it on the app’s page for a new one, and your users stay.
Step 2
Install the packages
npm install @authflowkit/sdk @authflowkit/ui@authflowkit/sdk is the SDK — the proxy, the provider, the hooks and the middleware. @authflowkit/ui is the ready-made screens.
The SDK has no required dependencies beyond zod: React and Next.js are both optional peers, so a backend that only mounts the proxy pulls in neither. @authflowkit/ui is React components, so it needs React 18.2 or 19 wherever you render them.
Step 3
Add the variables and the proxy route
This is the part that depends on your stack. Pick yours:
Environment
# .env.local — server-side only. Neither may carry NEXT_PUBLIC_.
AUTHFLOW_API_URL=https://api.authflow.wewiselabs.com
AUTHFLOW_SECRET_KEY=af_live_...The proxy route
// app/api/authflow/[...authflow]/route.ts
import { createAuthFlowHandler } from "@authflowkit/sdk/server";
export const { GET, POST } = createAuthFlowHandler();A catch-all route handler. createAuthFlowHandler() reads both variables from the environment for you.
The pages your emails link to
// app/verify/page.tsx — the verification email links here
"use client";
import { VerifyEmail } from "@authflowkit/ui";
export default function VerifyPage() {
// Confirming the address signs the user in, so send them into the app.
return <VerifyEmail redirectTo="/dashboard" />;
}// app/reset/page.tsx — the reset email links here
"use client";
import { ResetPassword } from "@authflowkit/ui";
export default function ResetPage() {
return <ResetPassword />;
}Reading the user on the server
// A Server Component — the user is in the first paint, no client fetch.
import { currentUser } from "@authflowkit/sdk/server";
import { redirect } from "next/navigation";
export default async function Page() {
const user = await currentUser();
if (!user) redirect("/sign-in");
return <p>Signed in as {user.email}</p>;
}Protecting routes
// middleware.ts
import { authMiddleware } from "@authflowkit/sdk/middleware";
export default authMiddleware({
// /verify and /reset must be public: whoever opens those links is,
// by definition, not signed in yet.
publicRoutes: ["/", "/sign-in", "/sign-up", "/verify", "/reset"],
});
export const config = { matcher: ["/((?!_next|.*\\..*).*)"] };The rest is the same everywhere
From here nothing depends on your stack. Wrap your app once, then drop the screens in wherever you want them.
// app/layout.tsx
import { AuthFlowProvider } from "@authflowkit/sdk";
import "@authflowkit/ui/styles.css";
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
<AuthFlowProvider>{children}</AuthFlowProvider>
</body>
</html>
);
}// app/sign-in/page.tsx
"use client";
import { SignIn } from "@authflowkit/ui";
export default function SignInPage() {
return <SignIn redirectTo="/dashboard" />;
}// app/sign-up/page.tsx
"use client";
import { SignUp } from "@authflowkit/ui";
export default function SignUpPage() {
return <SignUp />;
}That is a working sign-in page: validation, a loading state, a readable message for every error, and the two-factor step when a user has it turned on. The components already link to each other, and every link is a prop — see Components.
Reading the user
In the browser, from the provider’s state — this works in every stack:
"use client";
import { useUser } from "@authflowkit/sdk";
export function Greeting() {
const { status, user } = useUser();
// Render for loading rather than falling through to the signed-out view,
// or a signed-in user sees a sign-in button flash on every load.
if (status === "loading") return null;
return user ? <p>Hi, {user.email}</p> : null;
}Two-factor
Optional per user, and it ships in v1. Put <EnableTotp /> on a settings page and a signed-in user can turn it on: scan a QR code, confirm a code, and save ten recovery codes. From then on <SignIn /> asks for a code automatically — no extra route and no extra code.
Light and dark
The components are dark by default and ship a light theme too. To let visitors choose, add <ThemeScript />, <ThemeProvider> and a <ThemeToggle /> — see theming.