No description
Find a file
2026-02-06 18:26:04 -08:00
src Add initial library 2026-02-06 18:23:33 -08:00
.envrc Initial commit 2026-02-06 18:20:06 -08:00
.gitignore Initial commit 2026-02-06 18:20:06 -08:00
devenv.lock Initial commit 2026-02-06 18:20:06 -08:00
devenv.nix Initial commit 2026-02-06 18:20:06 -08:00
devenv.yaml Initial commit 2026-02-06 18:20:06 -08:00
package.json Add initial library 2026-02-06 18:23:33 -08:00
README.md Correct install instructions 2026-02-06 18:26:04 -08:00
requirements.md Initial commit 2026-02-06 18:20:06 -08:00
tsconfig.json Add initial library 2026-02-06 18:23:33 -08:00

sf-auth-nextjs-middleware

Nextjs middleware and App Router callback handler for sf-auth.

Install

npm install https://forgejo.snazzyfellas.com/snazzyfellas-public-libs/sf-auth-middleware-nextjs

Usage

Middleware

Create a middleware that redirects unauthenticated users to the sf-auth authenticate endpoint.

// middleware.ts
import { createSfAuthMiddleware } from "sf-auth-nextjs-middleware";

export const middleware = createSfAuthMiddleware(
  "https://your-site.com/auth_callback"
);

Callback route

Create an App Router route to handle the sf-auth callback, validate the one-time key, set cookies, and redirect to the desired page.

// app/auth_callback/route.ts
import { createSfAuthCallbackRoute } from "sf-auth-nextjs-middleware";

export const GET = createSfAuthCallbackRoute({
  redirectTo: "/user_info"
});

Configuration

Both helpers accept optional configuration to customize cookie names and endpoints.

import {
  createSfAuthMiddleware,
  createSfAuthCallbackRoute
} from "sf-auth-nextjs-middleware";

export const middleware = createSfAuthMiddleware(
  "https://your-site.com/auth_callback",
  {
    cookieNames: {
      userId: "sf_user_id",
      username: "sf_username"
    }
  }
);

export const GET = createSfAuthCallbackRoute({
  redirectTo: "/user_info",
  cookieNames: {
    userId: "sf_user_id",
    username: "sf_username"
  },
  validateEndpoint: "https://snazzyfellas.com/api/redirect/validate"
});