next-lite-auth 0.2.2 → 0.2.3

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 +28 -7
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -58,24 +58,38 @@ export const { GET, POST } = handlers;
58
58
 
59
59
  ### 3. Wrap root layout
60
60
 
61
+ `layout.tsx` is a Server Component — wrap `LiteAuthProvider` in a client component first:
62
+
61
63
  ```tsx
62
- // app/layout.tsx
64
+ // components/auth-provider.tsx
65
+ "use client";
63
66
  import { LiteAuthProvider } from "next-lite-auth/client";
64
67
 
68
+ export function AuthProvider({ children }: { children: React.ReactNode }) {
69
+ return (
70
+ <LiteAuthProvider protect={["/dashboard", "/settings"]} appName="My App">
71
+ {children}
72
+ </LiteAuthProvider>
73
+ );
74
+ }
75
+ ```
76
+
77
+ ```tsx
78
+ // app/layout.tsx
79
+ import { AuthProvider } from "@/components/auth-provider";
80
+
65
81
  export default function RootLayout({ children }: { children: React.ReactNode }) {
66
82
  return (
67
83
  <html>
68
84
  <body>
69
- <LiteAuthProvider protect={["/dashboard", "/settings"]}>
70
- {children}
71
- </LiteAuthProvider>
85
+ <AuthProvider>{children}</AuthProvider>
72
86
  </body>
73
87
  </html>
74
88
  );
75
89
  }
76
90
  ```
77
91
 
78
- **Done.** Visiting a protected route while logged out automatically shows the built-in login UI. After login, the original page renders instantly — no redirects, no separate login page needed.
92
+ **Done.** Visiting a protected route while logged out automatically shows the built-in login UI with your app name. After login, the original page renders instantly — no redirects, no separate login page needed.
79
93
 
80
94
  ---
81
95
 
@@ -97,10 +111,17 @@ LITE_AUTH_SECRET=your-secret
97
111
 
98
112
  ## Optional: server-side middleware
99
113
 
114
+ Strings protect exact and prefix routes. Use `"/"` to protect everything, or `RegExp` for dynamic routes:
115
+
100
116
  ```ts
101
117
  // middleware.ts
102
118
  import { middleware } from "@/auth";
103
- export default middleware({ protect: ["/dashboard", "/settings"] });
119
+
120
+ export default middleware({
121
+ protect: ["/dashboard", "/settings"], // string prefixes
122
+ // protect: ["/"], // protect all routes
123
+ // protect: [/^\/[^/]+\/name$/], // dynamic route /:id/name
124
+ });
104
125
 
105
126
  export const config = {
106
127
  matcher: ["/((?!_next|api/auth).*)"],
@@ -146,7 +167,7 @@ const user = await getUserFromCookies(cookies());
146
167
  | `handlers.GET / POST` | Catch-all route handlers |
147
168
  | `middleware(options)` | Edge middleware for server-side route protection |
148
169
  | `getUserFromCookies(cookies)` | Server-side session helper |
149
- | `LiteAuthProvider` | Root provider — manages session and auto-shows login UI |
170
+ | `LiteAuthProvider` | Root provider — manages session, auto-shows login UI (`appName`, `protect` props) |
150
171
  | `useLiteAuth()` | Hook — `user`, `loading`, `login`, `logout` |
151
172
 
152
173
  ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-lite-auth",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Lightweight JWT auth for Next.js using static JSON users (no database)",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",