Authfu

Quickstart · Next.js

Add Authfu with Auth.js v5

Connect a Next.js App Router project to Authfu using the @authfu/next provider and the standard Auth.js route handler.

Before you begin

Create an app in the Authfu console and register the callback URL your framework uses. For Auth.js, that URL ends in /api/auth/callback/authfu.

.env.local
AUTHFU_CLIENT_ID=...        # from the Authfu console
AUTHFU_CLIENT_SECRET=...    # from the Authfu console
AUTHFU_ISSUER=https://authfu.app   # optional; use http://localhost:3000 against a local provider
  1. Install the packages

    Install the Auth.js v5 beta and the Authfu provider package.

    shell
    npm install next-auth@beta @authfu/next
  2. Configure Auth.js

    Create the root auth module. With the SDK, credentials are read from the environment variables above.

    auth.ts
    // auth.ts
    import NextAuth from "next-auth"
    import { Authfu } from "@authfu/next"
    export const { handlers, auth, signIn, signOut } = NextAuth({ providers: [Authfu()] })
  3. Add the route handler

    Expose the handlers from the App Router catch-all route.

    app/api/auth/[...nextauth]/route.ts
    // app/api/auth/[...nextauth]/route.ts
    import { handlers } from "@/auth"
    export const { GET, POST } = handlers

What happens next

Auth.js handles your application session. Authfu handles hosted sign-in: the user enters an email, completes two-factor first when enabled, then receives a single-use magic link and returns to your callback.

Next steps