No description
| src | ||
| .envrc | ||
| .gitignore | ||
| devenv.lock | ||
| devenv.nix | ||
| devenv.yaml | ||
| package.json | ||
| README.md | ||
| requirements.md | ||
| tsconfig.json | ||
sf-auth-nextjs-middleware
Nextjs middleware and App Router callback handler for sf-auth.
Install
npm install sf-auth-nextjs-middleware
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"
});