Add README.md
This commit is contained in:
parent
e8a82796e0
commit
f55a450ce9
1 changed files with 70 additions and 0 deletions
70
README.md
Normal file
70
README.md
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
# sf-auth-nextjs-middleware
|
||||
|
||||
Nextjs middleware and App Router callback handler for sf-auth.
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
npm install sf-auth-nextjs-middleware
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Middleware
|
||||
|
||||
Create a middleware that redirects unauthenticated users to the sf-auth
|
||||
authenticate endpoint.
|
||||
|
||||
```ts
|
||||
// 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.
|
||||
|
||||
```ts
|
||||
// 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.
|
||||
|
||||
```ts
|
||||
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"
|
||||
});
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue