next-token-auth 1.0.12 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +34 -11
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -201,9 +201,9 @@ interface AuthConfig<User = unknown> {
201
201
  };
202
202
 
203
203
  routes?: {
204
- public: string[]; // always accessible, e.g. ["/", "/about"]
205
- protected: string[]; // require auth, supports wildcard: "/dashboard*"
206
- guestOnly?: string[]; // accessible only when NOT authenticated, e.g. ["/auth/login", "/auth/register"]
204
+ public: string[]; // always accessible regardless of auth state
205
+ protected: string[]; // require auth, supports wildcard: "/dashboard*"
206
+ guestOnly?: string[]; // only accessible when NOT authenticated any route name works
207
207
  loginPath?: string; // where to redirect unauthenticated users (default: "/login")
208
208
  redirectAuthenticatedTo?: string; // where to send authenticated users who hit a guestOnly route (default: "/dashboard")
209
209
  };
@@ -358,8 +358,10 @@ Unauthenticated requests are redirected to `/login` by default. Pass `{ redirect
358
358
  Protect entire route groups at the edge using Next.js middleware. The middleware supports three route categories:
359
359
 
360
360
  - `public` — always accessible, no auth check
361
- - `protected` — requires authentication, redirects to `/login` if not
362
- - `guestOnly` — accessible only when NOT authenticated (e.g. login, register pages); authenticated users are redirected away
361
+ - `protected` — requires authentication, redirects to `loginPath` if not
362
+ - `guestOnly` — accessible only when NOT authenticated; authenticated users are redirected to `redirectAuthenticatedTo`
363
+
364
+ You can use any route naming convention you want — the library doesn't enforce `/login`, `/dashboard`, or any specific path. Everything is driven by your config.
363
365
 
364
366
  ```ts
365
367
  // lib/auth.ts
@@ -367,10 +369,10 @@ export const authConfig: AuthConfig = {
367
369
  // ...
368
370
  routes: {
369
371
  public: ["/", "/about"],
370
- guestOnly: ["/auth/login", "/auth/register"], // authenticated users get redirected away
371
- protected: ["/dashboard*", "/profile*"],
372
- loginPath: "/auth/login", // where to redirect unauthenticated users
373
- redirectAuthenticatedTo: "/dashboard", // where to redirect authenticated users on guestOnly routes
372
+ guestOnly: ["/sign-in", "/sign-up"], // any names you want
373
+ protected: ["/app*", "/account*"],
374
+ loginPath: "/sign-in", // where unauthenticated users are sent
375
+ redirectAuthenticatedTo: "/app/home", // where authenticated users are sent from guestOnly routes
374
376
  },
375
377
  };
376
378
  ```
@@ -383,11 +385,30 @@ import { authConfig } from "@/lib/auth";
383
385
  export const middleware = authMiddleware(authConfig);
384
386
 
385
387
  export const config = {
386
- // Include all routes you want the middleware to run on
387
- matcher: ["/auth/login", "/auth/register", "/dashboard*", "/profile*"],
388
+ matcher: ["/sign-in", "/sign-up", "/app*", "/account*"],
388
389
  };
389
390
  ```
390
391
 
392
+ Some other valid setups:
393
+
394
+ ```ts
395
+ // Using /auth/* convention
396
+ routes: {
397
+ guestOnly: ["/auth/login", "/auth/register"],
398
+ protected: ["/dashboard*"],
399
+ loginPath: "/auth/login",
400
+ redirectAuthenticatedTo: "/dashboard",
401
+ }
402
+
403
+ // Using a portal pattern
404
+ routes: {
405
+ guestOnly: ["/portal"],
406
+ protected: ["/admin*", "/workspace*"],
407
+ loginPath: "/portal",
408
+ redirectAuthenticatedTo: "/admin",
409
+ }
410
+ ```
411
+
391
412
  Route resolution order inside the middleware:
392
413
 
393
414
  1. `guestOnly` — if authenticated, redirect to `redirectAuthenticatedTo`
@@ -398,6 +419,8 @@ Two things to keep in mind:
398
419
 
399
420
  - Wildcard patterns use `*` at the end: `"/dashboard*"` matches `/dashboard`, `/dashboard/`, and `/dashboard/settings`
400
421
  - The `matcher` in `export const config` controls which routes Next.js runs the middleware on at all — make sure it covers both your protected and guest-only routes
422
+ - `loginPath` defaults to `"/login"` if not set
423
+ - `redirectAuthenticatedTo` defaults to `"/dashboard"` if not set
401
424
 
402
425
  ---
403
426
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-token-auth",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "Production-grade authentication library for Next.js (App Router & Pages Router)",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",