@lumoauth/react 0.0.0-stage → 1.1.0

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.
package/dist/index.js ADDED
@@ -0,0 +1,2499 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ AuthCallback: () => AuthCallback,
25
+ LumoAuth: () => import_client4.LumoAuth,
26
+ LumoAuthProvider: () => LumoAuthProvider,
27
+ Protect: () => Protect,
28
+ RedirectToSignIn: () => RedirectToSignIn,
29
+ SignIn: () => SignIn,
30
+ SignInButton: () => SignInButton,
31
+ SignOutButton: () => SignOutButton,
32
+ SignUp: () => SignUp,
33
+ SignUpButton: () => SignUpButton,
34
+ SignedIn: () => SignedIn,
35
+ SignedOut: () => SignedOut,
36
+ UserAvatar: () => UserAvatar,
37
+ UserButton: () => UserButton,
38
+ UserProfile: () => UserProfile,
39
+ useAbac: () => useAbac,
40
+ useAuth: () => useAuth,
41
+ useEmailFirst: () => useEmailFirst,
42
+ useLumoAuth: () => useLumoAuth,
43
+ useMagicLink: () => useMagicLink,
44
+ usePermission: () => usePermission,
45
+ useSession: () => useSession,
46
+ useSignIn: () => useSignIn,
47
+ useUser: () => useUser,
48
+ useZanzibar: () => useZanzibar
49
+ });
50
+ module.exports = __toCommonJS(index_exports);
51
+ var import_client4 = require("@lumoauth/client");
52
+
53
+ // src/provider.tsx
54
+ var import_react = require("react");
55
+ var import_client = require("@lumoauth/client");
56
+ var import_client2 = require("@lumoauth/client");
57
+
58
+ // src/styles.ts
59
+ var STYLE_ID = "lumoauth-react-styles";
60
+ var injected = false;
61
+ function injectStyles() {
62
+ if (injected) return;
63
+ if (typeof document === "undefined") return;
64
+ if (document.getElementById(STYLE_ID)) {
65
+ injected = true;
66
+ return;
67
+ }
68
+ const style = document.createElement("style");
69
+ style.id = STYLE_ID;
70
+ style.textContent = CSS_CONTENT;
71
+ document.head.appendChild(style);
72
+ injected = true;
73
+ }
74
+ var CSS_CONTENT = `
75
+ /* \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
76
+ @lumoauth/react \u2014 Self-contained component styles
77
+ \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550 */
78
+
79
+ :root {
80
+ --la-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
81
+ --la-font-size-sm: 0.8125rem;
82
+ --la-font-size-base: 0.875rem;
83
+ --la-font-size-lg: 1rem;
84
+ --la-font-size-xl: 1.25rem;
85
+ --la-font-size-2xl: 1.5rem;
86
+ --la-font-weight-normal: 400;
87
+ --la-font-weight-medium: 500;
88
+ --la-font-weight-semibold: 600;
89
+
90
+ --la-radius-sm: 6px;
91
+ --la-radius-md: 8px;
92
+ --la-radius-lg: 12px;
93
+ --la-radius-xl: 16px;
94
+ --la-radius-full: 9999px;
95
+
96
+ --la-shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
97
+ --la-shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
98
+ --la-shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -2px rgba(0,0,0,0.04);
99
+ --la-shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
100
+
101
+ --la-transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
102
+
103
+ /* Light theme (default) */
104
+ --la-bg: #ffffff;
105
+ --la-bg-subtle: #f8f9fb;
106
+ --la-bg-muted: #f1f3f5;
107
+ --la-bg-hover: #e9ecef;
108
+ --la-border: #dee2e6;
109
+ --la-border-focus: #7c5cfc;
110
+ --la-text: #1a1a2e;
111
+ --la-text-secondary: #6c757d;
112
+ --la-text-muted: #adb5bd;
113
+ --la-primary: #7c5cfc;
114
+ --la-primary-hover: #6a4ce0;
115
+ --la-primary-text: #ffffff;
116
+ --la-danger: #e74c3c;
117
+ --la-danger-bg: #fef2f2;
118
+ --la-success: #27ae60;
119
+ --la-success-bg: #f0fdf4;
120
+ --la-link: #7c5cfc;
121
+ --la-overlay: rgba(0,0,0,0.5);
122
+ --la-card-shadow: var(--la-shadow-xl);
123
+ }
124
+
125
+ /* Dark theme */
126
+ [data-lumoauth-theme="dark"],
127
+ .la-dark {
128
+ --la-bg: #1a1a2e;
129
+ --la-bg-subtle: #16213e;
130
+ --la-bg-muted: #0f3460;
131
+ --la-bg-hover: #1a3a6a;
132
+ --la-border: #2a2a4a;
133
+ --la-border-focus: #9d85f7;
134
+ --la-text: #e8e8f0;
135
+ --la-text-secondary: #a0a0b8;
136
+ --la-text-muted: #6a6a88;
137
+ --la-primary: #9d85f7;
138
+ --la-primary-hover: #b39dff;
139
+ --la-primary-text: #1a1a2e;
140
+ --la-danger: #ff6b6b;
141
+ --la-danger-bg: #2d1b1b;
142
+ --la-success: #51cf66;
143
+ --la-success-bg: #1b2d1b;
144
+ --la-link: #9d85f7;
145
+ --la-overlay: rgba(0,0,0,0.7);
146
+ --la-card-shadow: 0 20px 25px -5px rgba(0,0,0,0.3), 0 10px 10px -5px rgba(0,0,0,0.2);
147
+ }
148
+
149
+ @media (prefers-color-scheme: dark) {
150
+ :root:not([data-lumoauth-theme="light"]):not(.la-light) {
151
+ --la-bg: #1a1a2e;
152
+ --la-bg-subtle: #16213e;
153
+ --la-bg-muted: #0f3460;
154
+ --la-bg-hover: #1a3a6a;
155
+ --la-border: #2a2a4a;
156
+ --la-border-focus: #9d85f7;
157
+ --la-text: #e8e8f0;
158
+ --la-text-secondary: #a0a0b8;
159
+ --la-text-muted: #6a6a88;
160
+ --la-primary: #9d85f7;
161
+ --la-primary-hover: #b39dff;
162
+ --la-primary-text: #1a1a2e;
163
+ --la-danger: #ff6b6b;
164
+ --la-danger-bg: #2d1b1b;
165
+ --la-success: #51cf66;
166
+ --la-success-bg: #1b2d1b;
167
+ --la-link: #9d85f7;
168
+ --la-overlay: rgba(0,0,0,0.7);
169
+ --la-card-shadow: 0 20px 25px -5px rgba(0,0,0,0.3), 0 10px 10px -5px rgba(0,0,0,0.2);
170
+ }
171
+ }
172
+
173
+ /* \u2500\u2500\u2500 Card Container \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
174
+
175
+ .la-card {
176
+ font-family: var(--la-font-family);
177
+ background: var(--la-bg);
178
+ border: 1px solid var(--la-border);
179
+ border-radius: var(--la-radius-xl);
180
+ box-shadow: var(--la-card-shadow);
181
+ width: 100%;
182
+ max-width: 400px;
183
+ padding: 2rem;
184
+ box-sizing: border-box;
185
+ color: var(--la-text);
186
+ }
187
+
188
+ .la-card * {
189
+ box-sizing: border-box;
190
+ }
191
+
192
+ .la-card-header {
193
+ text-align: center;
194
+ margin-bottom: 1.5rem;
195
+ }
196
+
197
+ .la-card-title {
198
+ font-size: var(--la-font-size-2xl);
199
+ font-weight: var(--la-font-weight-semibold);
200
+ color: var(--la-text);
201
+ margin: 0 0 0.25rem 0;
202
+ line-height: 1.3;
203
+ }
204
+
205
+ .la-card-subtitle {
206
+ font-size: var(--la-font-size-base);
207
+ color: var(--la-text-secondary);
208
+ margin: 0;
209
+ line-height: 1.5;
210
+ }
211
+
212
+ /* \u2500\u2500\u2500 Form Elements \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
213
+
214
+ .la-form-group {
215
+ margin-bottom: 1rem;
216
+ }
217
+
218
+ .la-label {
219
+ display: block;
220
+ font-size: var(--la-font-size-sm);
221
+ font-weight: var(--la-font-weight-medium);
222
+ color: var(--la-text);
223
+ margin-bottom: 0.375rem;
224
+ }
225
+
226
+ .la-input {
227
+ display: block;
228
+ width: 100%;
229
+ padding: 0.625rem 0.75rem;
230
+ font-family: var(--la-font-family);
231
+ font-size: var(--la-font-size-base);
232
+ color: var(--la-text);
233
+ background: var(--la-bg-subtle);
234
+ border: 1px solid var(--la-border);
235
+ border-radius: var(--la-radius-md);
236
+ outline: none;
237
+ transition: border-color var(--la-transition), box-shadow var(--la-transition);
238
+ line-height: 1.5;
239
+ }
240
+
241
+ .la-input::placeholder {
242
+ color: var(--la-text-muted);
243
+ }
244
+
245
+ .la-input:focus {
246
+ border-color: var(--la-border-focus);
247
+ box-shadow: 0 0 0 3px rgba(124, 92, 252, 0.15);
248
+ }
249
+
250
+ .la-input:disabled {
251
+ opacity: 0.6;
252
+ cursor: not-allowed;
253
+ }
254
+
255
+ /* \u2500\u2500\u2500 Buttons \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
256
+
257
+ .la-btn {
258
+ display: inline-flex;
259
+ align-items: center;
260
+ justify-content: center;
261
+ gap: 0.5rem;
262
+ width: 100%;
263
+ padding: 0.625rem 1rem;
264
+ font-family: var(--la-font-family);
265
+ font-size: var(--la-font-size-base);
266
+ font-weight: var(--la-font-weight-medium);
267
+ line-height: 1.5;
268
+ border-radius: var(--la-radius-md);
269
+ border: 1px solid transparent;
270
+ cursor: pointer;
271
+ transition: all var(--la-transition);
272
+ text-decoration: none;
273
+ outline: none;
274
+ }
275
+
276
+ .la-btn:focus-visible {
277
+ box-shadow: 0 0 0 3px rgba(124, 92, 252, 0.25);
278
+ }
279
+
280
+ .la-btn:disabled {
281
+ opacity: 0.6;
282
+ cursor: not-allowed;
283
+ }
284
+
285
+ .la-btn-primary {
286
+ background: var(--la-primary);
287
+ color: var(--la-primary-text);
288
+ border-color: var(--la-primary);
289
+ }
290
+
291
+ .la-btn-primary:hover:not(:disabled) {
292
+ background: var(--la-primary-hover);
293
+ border-color: var(--la-primary-hover);
294
+ }
295
+
296
+ .la-btn-outline {
297
+ background: transparent;
298
+ color: var(--la-text);
299
+ border-color: var(--la-border);
300
+ }
301
+
302
+ .la-btn-outline:hover:not(:disabled) {
303
+ background: var(--la-bg-hover);
304
+ }
305
+
306
+ .la-btn-ghost {
307
+ background: transparent;
308
+ color: var(--la-text-secondary);
309
+ border: none;
310
+ padding: 0.375rem 0.5rem;
311
+ width: auto;
312
+ }
313
+
314
+ .la-btn-ghost:hover:not(:disabled) {
315
+ color: var(--la-text);
316
+ background: var(--la-bg-hover);
317
+ }
318
+
319
+ .la-btn-danger {
320
+ background: transparent;
321
+ color: var(--la-danger);
322
+ border: none;
323
+ width: auto;
324
+ padding: 0.375rem 0.5rem;
325
+ }
326
+
327
+ .la-btn-danger:hover:not(:disabled) {
328
+ background: var(--la-danger-bg);
329
+ }
330
+
331
+ /* \u2500\u2500\u2500 Spinner \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
332
+
333
+ .la-spinner {
334
+ display: inline-block;
335
+ width: 1rem;
336
+ height: 1rem;
337
+ border: 2px solid var(--la-border);
338
+ border-top-color: var(--la-primary);
339
+ border-radius: 50%;
340
+ animation: la-spin 0.6s linear infinite;
341
+ }
342
+
343
+ .la-spinner-sm {
344
+ width: 0.75rem;
345
+ height: 0.75rem;
346
+ border-width: 1.5px;
347
+ }
348
+
349
+ @keyframes la-spin {
350
+ to { transform: rotate(360deg); }
351
+ }
352
+
353
+ /* \u2500\u2500\u2500 Alert / Error \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
354
+
355
+ .la-alert {
356
+ padding: 0.625rem 0.75rem;
357
+ border-radius: var(--la-radius-md);
358
+ font-size: var(--la-font-size-sm);
359
+ line-height: 1.5;
360
+ margin-bottom: 1rem;
361
+ }
362
+
363
+ .la-alert-error {
364
+ background: var(--la-danger-bg);
365
+ color: var(--la-danger);
366
+ border: 1px solid rgba(231, 76, 60, 0.15);
367
+ }
368
+
369
+ .la-alert-success {
370
+ background: var(--la-success-bg);
371
+ color: var(--la-success);
372
+ border: 1px solid rgba(39, 174, 96, 0.15);
373
+ }
374
+
375
+ /* \u2500\u2500\u2500 Divider \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
376
+
377
+ .la-divider {
378
+ display: flex;
379
+ align-items: center;
380
+ gap: 0.75rem;
381
+ margin: 1.25rem 0;
382
+ color: var(--la-text-muted);
383
+ font-size: var(--la-font-size-sm);
384
+ }
385
+
386
+ .la-divider::before,
387
+ .la-divider::after {
388
+ content: '';
389
+ flex: 1;
390
+ height: 1px;
391
+ background: var(--la-border);
392
+ }
393
+
394
+ /* \u2500\u2500\u2500 Social Button \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
395
+
396
+ .la-social-btn {
397
+ display: flex;
398
+ align-items: center;
399
+ justify-content: center;
400
+ gap: 0.5rem;
401
+ width: 100%;
402
+ padding: 0.5rem 0.75rem;
403
+ font-family: var(--la-font-family);
404
+ font-size: var(--la-font-size-sm);
405
+ font-weight: var(--la-font-weight-medium);
406
+ color: var(--la-text);
407
+ background: var(--la-bg);
408
+ border: 1px solid var(--la-border);
409
+ border-radius: var(--la-radius-md);
410
+ cursor: pointer;
411
+ transition: all var(--la-transition);
412
+ outline: none;
413
+ line-height: 1.5;
414
+ }
415
+
416
+ .la-social-btn:hover {
417
+ background: var(--la-bg-hover);
418
+ }
419
+
420
+ .la-social-btn:focus-visible {
421
+ box-shadow: 0 0 0 3px rgba(124, 92, 252, 0.15);
422
+ }
423
+
424
+ .la-social-buttons {
425
+ display: flex;
426
+ flex-direction: column;
427
+ gap: 0.5rem;
428
+ margin-bottom: 0.25rem;
429
+ }
430
+
431
+ .la-social-icon {
432
+ width: 1.125rem;
433
+ height: 1.125rem;
434
+ flex-shrink: 0;
435
+ }
436
+
437
+ /* \u2500\u2500\u2500 Footer Link \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
438
+
439
+ .la-footer {
440
+ text-align: center;
441
+ margin-top: 1.25rem;
442
+ font-size: var(--la-font-size-sm);
443
+ color: var(--la-text-secondary);
444
+ }
445
+
446
+ .la-footer a,
447
+ .la-link {
448
+ color: var(--la-link);
449
+ text-decoration: none;
450
+ font-weight: var(--la-font-weight-medium);
451
+ cursor: pointer;
452
+ }
453
+
454
+ .la-footer a:hover,
455
+ .la-link:hover {
456
+ text-decoration: underline;
457
+ }
458
+
459
+ /* \u2500\u2500\u2500 Password Strength \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
460
+
461
+ .la-password-strength {
462
+ margin-top: 0.375rem;
463
+ }
464
+
465
+ .la-password-bar {
466
+ height: 3px;
467
+ border-radius: 2px;
468
+ background: var(--la-bg-muted);
469
+ overflow: hidden;
470
+ }
471
+
472
+ .la-password-fill {
473
+ height: 100%;
474
+ border-radius: 2px;
475
+ transition: width var(--la-transition), background var(--la-transition);
476
+ }
477
+
478
+ .la-password-fill[data-strength="0"] { width: 0%; }
479
+ .la-password-fill[data-strength="1"] { width: 25%; background: var(--la-danger); }
480
+ .la-password-fill[data-strength="2"] { width: 50%; background: #f39c12; }
481
+ .la-password-fill[data-strength="3"] { width: 75%; background: #3498db; }
482
+ .la-password-fill[data-strength="4"] { width: 100%; background: var(--la-success); }
483
+
484
+ .la-password-label {
485
+ font-size: 0.6875rem;
486
+ color: var(--la-text-muted);
487
+ margin-top: 0.25rem;
488
+ }
489
+
490
+ /* \u2500\u2500\u2500 UserButton \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
491
+
492
+ .la-user-button {
493
+ position: relative;
494
+ display: inline-flex;
495
+ font-family: var(--la-font-family);
496
+ }
497
+
498
+ .la-user-trigger {
499
+ display: flex;
500
+ align-items: center;
501
+ gap: 0.5rem;
502
+ padding: 0.25rem;
503
+ background: none;
504
+ border: none;
505
+ cursor: pointer;
506
+ border-radius: var(--la-radius-full);
507
+ transition: all var(--la-transition);
508
+ outline: none;
509
+ }
510
+
511
+ .la-user-trigger:hover {
512
+ background: var(--la-bg-hover);
513
+ }
514
+
515
+ .la-user-trigger:focus-visible {
516
+ box-shadow: 0 0 0 3px rgba(124, 92, 252, 0.25);
517
+ }
518
+
519
+ .la-user-avatar {
520
+ width: 2rem;
521
+ height: 2rem;
522
+ border-radius: 50%;
523
+ background: var(--la-primary);
524
+ color: var(--la-primary-text);
525
+ display: flex;
526
+ align-items: center;
527
+ justify-content: center;
528
+ font-size: var(--la-font-size-sm);
529
+ font-weight: var(--la-font-weight-semibold);
530
+ overflow: hidden;
531
+ flex-shrink: 0;
532
+ }
533
+
534
+ .la-user-avatar img {
535
+ width: 100%;
536
+ height: 100%;
537
+ object-fit: cover;
538
+ }
539
+
540
+ .la-user-name {
541
+ font-size: var(--la-font-size-sm);
542
+ font-weight: var(--la-font-weight-medium);
543
+ color: var(--la-text);
544
+ }
545
+
546
+ .la-user-dropdown {
547
+ position: absolute;
548
+ top: calc(100% + 0.5rem);
549
+ right: 0;
550
+ min-width: 220px;
551
+ background: var(--la-bg);
552
+ border: 1px solid var(--la-border);
553
+ border-radius: var(--la-radius-lg);
554
+ box-shadow: var(--la-shadow-lg);
555
+ padding: 0.375rem;
556
+ z-index: 9999;
557
+ animation: la-dropdown-in 0.15s ease-out;
558
+ }
559
+
560
+ @keyframes la-dropdown-in {
561
+ from {
562
+ opacity: 0;
563
+ transform: translateY(-4px) scale(0.97);
564
+ }
565
+ to {
566
+ opacity: 1;
567
+ transform: translateY(0) scale(1);
568
+ }
569
+ }
570
+
571
+ .la-user-dropdown-header {
572
+ padding: 0.5rem 0.625rem;
573
+ border-bottom: 1px solid var(--la-border);
574
+ margin-bottom: 0.25rem;
575
+ }
576
+
577
+ .la-user-dropdown-email {
578
+ font-size: var(--la-font-size-sm);
579
+ color: var(--la-text-secondary);
580
+ overflow: hidden;
581
+ text-overflow: ellipsis;
582
+ white-space: nowrap;
583
+ }
584
+
585
+ .la-user-dropdown-name {
586
+ font-size: var(--la-font-size-sm);
587
+ font-weight: var(--la-font-weight-medium);
588
+ color: var(--la-text);
589
+ }
590
+
591
+ .la-dropdown-item {
592
+ display: flex;
593
+ align-items: center;
594
+ gap: 0.5rem;
595
+ width: 100%;
596
+ padding: 0.5rem 0.625rem;
597
+ font-family: var(--la-font-family);
598
+ font-size: var(--la-font-size-sm);
599
+ color: var(--la-text);
600
+ background: none;
601
+ border: none;
602
+ border-radius: var(--la-radius-sm);
603
+ cursor: pointer;
604
+ transition: background var(--la-transition);
605
+ text-align: left;
606
+ outline: none;
607
+ }
608
+
609
+ .la-dropdown-item:hover {
610
+ background: var(--la-bg-hover);
611
+ }
612
+
613
+ .la-dropdown-item-danger {
614
+ color: var(--la-danger);
615
+ }
616
+
617
+ .la-dropdown-item-danger:hover {
618
+ background: var(--la-danger-bg);
619
+ }
620
+
621
+ .la-dropdown-divider {
622
+ height: 1px;
623
+ background: var(--la-border);
624
+ margin: 0.25rem 0;
625
+ }
626
+
627
+ /* \u2500\u2500\u2500 Protect Loading \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
628
+
629
+ .la-protect-loading {
630
+ display: flex;
631
+ align-items: center;
632
+ justify-content: center;
633
+ padding: 1rem;
634
+ }
635
+
636
+ /* \u2500\u2500\u2500 Forgot Password Link \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
637
+
638
+ .la-forgot {
639
+ text-align: right;
640
+ margin-top: -0.5rem;
641
+ margin-bottom: 1rem;
642
+ }
643
+
644
+ .la-forgot a {
645
+ font-size: var(--la-font-size-sm);
646
+ color: var(--la-link);
647
+ text-decoration: none;
648
+ }
649
+
650
+ .la-forgot a:hover {
651
+ text-decoration: underline;
652
+ }
653
+
654
+ /* \u2500\u2500\u2500 UserAvatar (standalone) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
655
+
656
+ .la-avatar {
657
+ display: inline-flex;
658
+ align-items: center;
659
+ justify-content: center;
660
+ font-family: var(--la-font-family);
661
+ font-weight: var(--la-font-weight-semibold);
662
+ color: #fff;
663
+ background: var(--la-primary);
664
+ overflow: hidden;
665
+ flex-shrink: 0;
666
+ user-select: none;
667
+ line-height: 1;
668
+ }
669
+
670
+ .la-avatar img {
671
+ width: 100%;
672
+ height: 100%;
673
+ object-fit: cover;
674
+ }
675
+
676
+ .la-avatar-circle {
677
+ border-radius: var(--la-radius-full);
678
+ }
679
+
680
+ .la-avatar-square {
681
+ border-radius: var(--la-radius-md);
682
+ }
683
+
684
+ /* \u2500\u2500\u2500 UserProfile Card \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
685
+
686
+ .la-profile-card {
687
+ max-width: 420px;
688
+ }
689
+
690
+ .la-profile-header {
691
+ display: flex;
692
+ align-items: center;
693
+ gap: 1rem;
694
+ padding-bottom: 1.25rem;
695
+ border-bottom: 1px solid var(--la-border);
696
+ margin-bottom: 1rem;
697
+ }
698
+
699
+ .la-profile-avatar {
700
+ width: 56px;
701
+ height: 56px;
702
+ font-size: 1.25rem;
703
+ flex-shrink: 0;
704
+ }
705
+
706
+ .la-profile-avatar img {
707
+ width: 100%;
708
+ height: 100%;
709
+ object-fit: cover;
710
+ }
711
+
712
+ .la-profile-header-info {
713
+ min-width: 0;
714
+ }
715
+
716
+ .la-profile-name {
717
+ font-size: var(--la-font-size-lg);
718
+ font-weight: var(--la-font-weight-semibold);
719
+ color: var(--la-text-primary);
720
+ line-height: 1.3;
721
+ overflow: hidden;
722
+ text-overflow: ellipsis;
723
+ white-space: nowrap;
724
+ }
725
+
726
+ .la-profile-email {
727
+ font-size: var(--la-font-size-sm);
728
+ color: var(--la-text-secondary);
729
+ overflow: hidden;
730
+ text-overflow: ellipsis;
731
+ white-space: nowrap;
732
+ }
733
+
734
+ .la-profile-section {
735
+ margin-bottom: 1rem;
736
+ }
737
+
738
+ .la-profile-section-title {
739
+ font-size: var(--la-font-size-sm);
740
+ font-weight: var(--la-font-weight-semibold);
741
+ color: var(--la-text-secondary);
742
+ text-transform: uppercase;
743
+ letter-spacing: 0.05em;
744
+ margin-bottom: 0.625rem;
745
+ }
746
+
747
+ .la-profile-row {
748
+ display: flex;
749
+ align-items: center;
750
+ gap: 0.625rem;
751
+ padding: 0.5rem 0;
752
+ font-size: var(--la-font-size-base);
753
+ color: var(--la-text-primary);
754
+ }
755
+
756
+ .la-profile-row svg {
757
+ color: var(--la-text-secondary);
758
+ flex-shrink: 0;
759
+ }
760
+
761
+ .la-profile-row-label {
762
+ color: var(--la-text-secondary);
763
+ min-width: 3.5rem;
764
+ flex-shrink: 0;
765
+ }
766
+
767
+ .la-profile-row-value {
768
+ flex: 1;
769
+ min-width: 0;
770
+ overflow: hidden;
771
+ text-overflow: ellipsis;
772
+ white-space: nowrap;
773
+ }
774
+
775
+ .la-profile-badge {
776
+ display: inline-flex;
777
+ align-items: center;
778
+ gap: 0.25rem;
779
+ font-size: 0.75rem;
780
+ font-weight: var(--la-font-weight-medium);
781
+ padding: 0.125rem 0.5rem;
782
+ border-radius: var(--la-radius-full);
783
+ flex-shrink: 0;
784
+ }
785
+
786
+ .la-badge-success {
787
+ background: #dcfce7;
788
+ color: #166534;
789
+ }
790
+
791
+ .la-badge-warning {
792
+ background: #fef9c3;
793
+ color: #854d0e;
794
+ }
795
+
796
+ .la-badge-muted {
797
+ background: var(--la-bg-muted);
798
+ color: var(--la-text-secondary);
799
+ }
800
+
801
+ .la-dark .la-badge-success {
802
+ background: rgba(22, 163, 74, 0.15);
803
+ color: #4ade80;
804
+ }
805
+
806
+ .la-dark .la-badge-warning {
807
+ background: rgba(234, 179, 8, 0.15);
808
+ color: #facc15;
809
+ }
810
+
811
+ .la-dark .la-badge-muted {
812
+ background: rgba(255, 255, 255, 0.08);
813
+ color: var(--la-text-secondary);
814
+ }
815
+
816
+ .la-profile-tags {
817
+ display: flex;
818
+ flex-wrap: wrap;
819
+ gap: 0.375rem;
820
+ flex: 1;
821
+ }
822
+
823
+ .la-profile-tag {
824
+ display: inline-block;
825
+ font-size: 0.75rem;
826
+ font-weight: var(--la-font-weight-medium);
827
+ padding: 0.125rem 0.5rem;
828
+ border-radius: var(--la-radius-full);
829
+ background: var(--la-bg-muted);
830
+ color: var(--la-text-secondary);
831
+ border: 1px solid var(--la-border);
832
+ }
833
+
834
+ .la-profile-actions {
835
+ padding-top: 0.5rem;
836
+ border-top: 1px solid var(--la-border);
837
+ margin-top: 0.5rem;
838
+ }
839
+
840
+ .la-profile-signout-btn {
841
+ width: 100%;
842
+ display: flex;
843
+ align-items: center;
844
+ justify-content: center;
845
+ gap: 0.5rem;
846
+ }
847
+
848
+ .la-btn-outline {
849
+ background: transparent;
850
+ border: 1px solid var(--la-border);
851
+ color: var(--la-text-primary);
852
+ padding: 0.625rem 1rem;
853
+ border-radius: var(--la-radius-md);
854
+ font-size: var(--la-font-size-base);
855
+ font-weight: var(--la-font-weight-medium);
856
+ cursor: pointer;
857
+ transition: background var(--la-transition), border-color var(--la-transition);
858
+ }
859
+
860
+ .la-btn-outline:hover {
861
+ background: var(--la-bg-hover);
862
+ border-color: var(--la-text-secondary);
863
+ }
864
+
865
+ .la-btn-outline:disabled {
866
+ opacity: 0.5;
867
+ cursor: not-allowed;
868
+ }
869
+ `;
870
+
871
+ // src/provider.tsx
872
+ var import_jsx_runtime = require("react/jsx-runtime");
873
+ var LumoAuthContext = (0, import_react.createContext)(null);
874
+ LumoAuthContext.displayName = "LumoAuthContext";
875
+ function useLumoAuthContext() {
876
+ const ctx = (0, import_react.useContext)(LumoAuthContext);
877
+ if (!ctx) {
878
+ throw new Error(
879
+ 'useLumoAuthContext must be used within <LumoAuthProvider>. Wrap your application with <LumoAuthProvider domain="..." orgId="..." clientId="...">.'
880
+ );
881
+ }
882
+ return ctx;
883
+ }
884
+ var PKCE_VERIFIER_KEY = "lumoauth_pkce_verifier";
885
+ var PKCE_STATE_KEY = "lumoauth_pkce_state";
886
+ function savePkceParams(codeVerifier, state) {
887
+ try {
888
+ if (typeof window !== "undefined") {
889
+ sessionStorage.setItem(PKCE_VERIFIER_KEY, codeVerifier);
890
+ sessionStorage.setItem(PKCE_STATE_KEY, state);
891
+ }
892
+ } catch {
893
+ }
894
+ }
895
+ function loadPkceParams() {
896
+ try {
897
+ if (typeof window !== "undefined") {
898
+ return {
899
+ codeVerifier: sessionStorage.getItem(PKCE_VERIFIER_KEY),
900
+ state: sessionStorage.getItem(PKCE_STATE_KEY)
901
+ };
902
+ }
903
+ } catch {
904
+ }
905
+ return { codeVerifier: null, state: null };
906
+ }
907
+ function clearPkceParams() {
908
+ try {
909
+ if (typeof window !== "undefined") {
910
+ sessionStorage.removeItem(PKCE_VERIFIER_KEY);
911
+ sessionStorage.removeItem(PKCE_STATE_KEY);
912
+ }
913
+ } catch {
914
+ }
915
+ }
916
+ function parseUserFromUserInfo(data) {
917
+ const firstName = data.given_name || data.first_name || "";
918
+ const lastName = data.family_name || data.last_name || "";
919
+ const email = data.email || "";
920
+ const displayName = data.name || [firstName, lastName].filter(Boolean).join(" ") || email;
921
+ return {
922
+ id: data.sub || data.id || "",
923
+ email,
924
+ firstName: firstName || void 0,
925
+ lastName: lastName || void 0,
926
+ displayName,
927
+ avatarUrl: data.picture || void 0,
928
+ emailVerified: data.email_verified ?? false,
929
+ mfaEnabled: data.mfa_enabled ?? false,
930
+ roles: Array.isArray(data.roles) ? data.roles : [],
931
+ groups: Array.isArray(data.groups) ? data.groups : [],
932
+ sub: data.sub || void 0,
933
+ claims: data
934
+ };
935
+ }
936
+ var DEFAULT_SCOPE = "openid profile email";
937
+ function LumoAuthProvider({
938
+ domain,
939
+ orgId,
940
+ clientId,
941
+ authStrategy = "pkce",
942
+ redirectUri,
943
+ scope = DEFAULT_SCOPE,
944
+ afterSignInUrl,
945
+ afterSignUpUrl,
946
+ afterSignOutUrl,
947
+ storage,
948
+ crossTab = true,
949
+ children
950
+ }) {
951
+ const [user, setUser] = (0, import_react.useState)(null);
952
+ const tokensRef = (0, import_react.useRef)({ accessToken: null, refreshToken: null, expiresAt: null, idToken: null });
953
+ const callbackHandledRef = (0, import_react.useRef)(false);
954
+ const callbackInflightRef = (0, import_react.useRef)(null);
955
+ (0, import_react.useEffect)(() => {
956
+ injectStyles();
957
+ }, []);
958
+ const authModule = (0, import_react.useMemo)(
959
+ () => new import_client2.AuthModule({
960
+ baseUrl: domain,
961
+ orgId,
962
+ clientId
963
+ }),
964
+ [domain, orgId, clientId]
965
+ );
966
+ const resolvedRedirectUri = (0, import_react.useMemo)(() => {
967
+ if (redirectUri) return redirectUri;
968
+ if (typeof window !== "undefined") {
969
+ return `${window.location.origin}/auth/callback`;
970
+ }
971
+ return "";
972
+ }, [redirectUri]);
973
+ const session = (0, import_react.useMemo)(
974
+ () => new import_client.LumoAuthSession({
975
+ auth: authModule,
976
+ redirectUri: resolvedRedirectUri,
977
+ storage,
978
+ crossTab,
979
+ // Mirror the store's tokens into the ref the flow code below
980
+ // still reads, so signOut can build id_token_hint and the
981
+ // callback path can inspect what was persisted.
982
+ onTokens: (t) => {
983
+ tokensRef.current = {
984
+ accessToken: t.accessToken,
985
+ refreshToken: t.refreshToken,
986
+ idToken: t.idToken,
987
+ expiresAt: t.expiresAt
988
+ };
989
+ }
990
+ }),
991
+ [authModule, resolvedRedirectUri, storage, crossTab]
992
+ );
993
+ (0, import_react.useEffect)(() => () => session.dispose(), [session]);
994
+ const sessionState = (0, import_react.useSyncExternalStore)(
995
+ session.subscribe,
996
+ session.getSnapshot,
997
+ session.getServerSnapshot
998
+ );
999
+ const state = (0, import_react.useMemo)(
1000
+ () => ({
1001
+ status: sessionState.status,
1002
+ user: sessionState.isSignedIn ? user : null,
1003
+ isLoaded: sessionState.isLoaded,
1004
+ isSignedIn: sessionState.isSignedIn
1005
+ }),
1006
+ [sessionState, user]
1007
+ );
1008
+ const dispatch = (0, import_react.useCallback)(
1009
+ (action) => {
1010
+ if (action.type === "AUTHENTICATED") setUser(action.user);
1011
+ else if (action.type === "UNAUTHENTICATED" || action.type === "ERROR") setUser(null);
1012
+ },
1013
+ []
1014
+ );
1015
+ const fetchUser = (0, import_react.useCallback)(async (accessToken) => {
1016
+ const data = await authModule.getUserInfo(accessToken);
1017
+ return parseUserFromUserInfo(data);
1018
+ }, [authModule]);
1019
+ const refreshAccessToken = (0, import_react.useCallback)(
1020
+ () => session.refresh(),
1021
+ [session]
1022
+ );
1023
+ const getToken = (0, import_react.useCallback)(
1024
+ () => session.getToken(),
1025
+ [session]
1026
+ );
1027
+ const signInWithRedirect = (0, import_react.useCallback)(() => {
1028
+ authModule.buildAuthorizationUrl({
1029
+ redirectUri: resolvedRedirectUri,
1030
+ scope
1031
+ }).then(({ url, codeVerifier, state: stateParam }) => {
1032
+ savePkceParams(codeVerifier, stateParam);
1033
+ if (typeof window !== "undefined") {
1034
+ window.location.href = url;
1035
+ }
1036
+ });
1037
+ }, [authModule, resolvedRedirectUri, scope]);
1038
+ const signInWithSocial = (0, import_react.useCallback)((provider) => {
1039
+ authModule.buildAuthorizationUrl({
1040
+ redirectUri: resolvedRedirectUri,
1041
+ scope,
1042
+ extraParams: { provider }
1043
+ }).then(({ url, codeVerifier, state: stateParam }) => {
1044
+ savePkceParams(codeVerifier, stateParam);
1045
+ if (typeof window !== "undefined") {
1046
+ window.location.href = url;
1047
+ }
1048
+ });
1049
+ }, [authModule, resolvedRedirectUri, scope]);
1050
+ const signIn = (0, import_react.useCallback)(async (email, password) => {
1051
+ if (authStrategy === "pkce" || !email && !password) {
1052
+ signInWithRedirect();
1053
+ return;
1054
+ }
1055
+ if (!email || !password) {
1056
+ throw new Error("Email and password are required for password-based sign-in");
1057
+ }
1058
+ dispatch({ type: "LOADING" });
1059
+ try {
1060
+ const data = await authModule.passwordGrant(
1061
+ email,
1062
+ password,
1063
+ scope,
1064
+ redirectUri
1065
+ );
1066
+ await session.adopt(data);
1067
+ const user2 = await fetchUser(data.access_token);
1068
+ dispatch({ type: "AUTHENTICATED", user: user2 });
1069
+ } catch (err) {
1070
+ dispatch({ type: "ERROR", error: err instanceof Error ? err.message : "Sign in failed" });
1071
+ throw err;
1072
+ }
1073
+ }, [authStrategy, authModule, redirectUri, scope, fetchUser, session, signInWithRedirect, dispatch]);
1074
+ const handleCallback = (0, import_react.useCallback)(async () => {
1075
+ if (typeof window === "undefined") return;
1076
+ const params = new URLSearchParams(window.location.search);
1077
+ const code = params.get("code");
1078
+ if (code && callbackInflightRef.current?.code === code) {
1079
+ return callbackInflightRef.current.promise;
1080
+ }
1081
+ const promise = (async () => {
1082
+ const returnedState = params.get("state");
1083
+ const error = params.get("error");
1084
+ const errorDescription = params.get("error_description");
1085
+ if (error) {
1086
+ dispatch({ type: "ERROR", error: errorDescription || error });
1087
+ throw new Error(errorDescription || error);
1088
+ }
1089
+ if (!code) {
1090
+ dispatch({ type: "ERROR", error: "No authorization code found in callback URL" });
1091
+ throw new Error("No authorization code found in callback URL");
1092
+ }
1093
+ const { codeVerifier, state: savedState } = loadPkceParams();
1094
+ if (!savedState || savedState !== returnedState) {
1095
+ clearPkceParams();
1096
+ dispatch({ type: "ERROR", error: "Invalid state parameter \u2014 possible CSRF attack" });
1097
+ throw new Error("Invalid state parameter \u2014 possible CSRF attack");
1098
+ }
1099
+ if (!codeVerifier) {
1100
+ clearPkceParams();
1101
+ dispatch({ type: "ERROR", error: "No PKCE code verifier found" });
1102
+ throw new Error("No PKCE code verifier found");
1103
+ }
1104
+ dispatch({ type: "LOADING" });
1105
+ try {
1106
+ const data = await authModule.exchangeCodeForTokens({
1107
+ code,
1108
+ codeVerifier,
1109
+ redirectUri: resolvedRedirectUri
1110
+ });
1111
+ clearPkceParams();
1112
+ await session.adopt(data);
1113
+ const user2 = await fetchUser(data.access_token);
1114
+ dispatch({ type: "AUTHENTICATED", user: user2 });
1115
+ } catch (err) {
1116
+ clearPkceParams();
1117
+ dispatch({ type: "ERROR", error: err instanceof Error ? err.message : "Token exchange failed" });
1118
+ throw err;
1119
+ }
1120
+ })();
1121
+ if (code) {
1122
+ callbackInflightRef.current = { code, promise };
1123
+ promise.catch(() => {
1124
+ if (callbackInflightRef.current?.promise === promise) {
1125
+ callbackInflightRef.current = null;
1126
+ }
1127
+ });
1128
+ }
1129
+ return promise;
1130
+ }, [authModule, resolvedRedirectUri, fetchUser, session, dispatch]);
1131
+ const signUp = (0, import_react.useCallback)(async (_params) => {
1132
+ if (authStrategy === "pkce") {
1133
+ const safeOrgId = encodeURIComponent(orgId);
1134
+ const signUpUrl = `${domain.replace(/\/+$/, "")}/orgs/${safeOrgId}/register?` + new URLSearchParams({
1135
+ client_id: clientId,
1136
+ redirect_uri: resolvedRedirectUri,
1137
+ response_type: "code",
1138
+ scope
1139
+ }).toString();
1140
+ if (typeof window !== "undefined") {
1141
+ window.location.href = signUpUrl;
1142
+ }
1143
+ return;
1144
+ }
1145
+ dispatch({
1146
+ type: "ERROR",
1147
+ error: "inline_registration_unsupported"
1148
+ });
1149
+ throw new Error(
1150
+ `Inline registration is not supported by this LumoAuth server: there is no JSON registration endpoint. Use redirectToSignUp() to send the user to the hosted registration page (${domain.replace(/\/+$/, "")}/orgs/${encodeURIComponent(orgId)}/register), or set authStrategy: "pkce".`
1151
+ );
1152
+ }, [authStrategy, domain, orgId, clientId, resolvedRedirectUri, scope, signIn]);
1153
+ const sendMagicLink = (0, import_react.useCallback)(async (email, redirectUri2) => {
1154
+ await authModule.requestMagicLink({ email, redirectUri: redirectUri2 });
1155
+ }, [authModule]);
1156
+ const checkEmail = (0, import_react.useCallback)(
1157
+ (email) => authModule.checkEmailExists(email),
1158
+ [authModule]
1159
+ );
1160
+ const signOut = (0, import_react.useCallback)(async (options) => {
1161
+ const { accessToken, idToken } = tokensRef.current;
1162
+ if (typeof window === "undefined") {
1163
+ if (accessToken) {
1164
+ authModule.revokeToken(accessToken, accessToken).catch(() => {
1165
+ });
1166
+ }
1167
+ tokensRef.current = { accessToken: null, refreshToken: null, expiresAt: null, idToken: null };
1168
+ await session.clearSession();
1169
+ dispatch({ type: "UNAUTHENTICATED" });
1170
+ return;
1171
+ }
1172
+ const targetUrl = options?.afterSignOutUrl || afterSignOutUrl || "/";
1173
+ const postLogoutRedirectUri = new URL(targetUrl, window.location.origin).toString();
1174
+ const safeOrgId = encodeURIComponent(orgId);
1175
+ const params = new URLSearchParams({
1176
+ post_logout_redirect_uri: postLogoutRedirectUri
1177
+ });
1178
+ if (idToken) {
1179
+ params.set("id_token_hint", idToken);
1180
+ }
1181
+ const logoutUrl = `${domain.replace(/\/+$/, "")}/orgs/${safeOrgId}/api/v1/oauth/logout?${params.toString()}`;
1182
+ if (accessToken) {
1183
+ authModule.revokeToken(accessToken, accessToken).catch(() => {
1184
+ });
1185
+ }
1186
+ tokensRef.current = { accessToken: null, refreshToken: null, expiresAt: null, idToken: null };
1187
+ await session.clearSession(null, { emit: false });
1188
+ window.location.replace(logoutUrl);
1189
+ await new Promise(() => {
1190
+ });
1191
+ }, [authModule, domain, orgId, afterSignOutUrl, session, dispatch]);
1192
+ (0, import_react.useEffect)(() => {
1193
+ let cancelled = false;
1194
+ async function init() {
1195
+ if (typeof window === "undefined") return;
1196
+ const params = new URLSearchParams(window.location.search);
1197
+ const code = params.get("code");
1198
+ const returnedState = params.get("state");
1199
+ if (code && returnedState) {
1200
+ if (callbackHandledRef.current) return;
1201
+ callbackHandledRef.current = true;
1202
+ try {
1203
+ await handleCallback();
1204
+ if (cancelled) return;
1205
+ params.delete("code");
1206
+ params.delete("state");
1207
+ params.delete("iss");
1208
+ const cleanUrl = params.toString() ? `${window.location.pathname}?${params}` : window.location.pathname;
1209
+ window.history.replaceState({}, "", cleanUrl);
1210
+ return;
1211
+ } catch {
1212
+ callbackHandledRef.current = false;
1213
+ if (!cancelled) dispatch({ type: "UNAUTHENTICATED" });
1214
+ return;
1215
+ }
1216
+ }
1217
+ }
1218
+ init().then(() => {
1219
+ if (!cancelled) void session.hydrate();
1220
+ });
1221
+ return () => {
1222
+ cancelled = true;
1223
+ };
1224
+ }, [fetchUser, handleCallback, refreshAccessToken, session]);
1225
+ (0, import_react.useEffect)(() => {
1226
+ let cancelled = false;
1227
+ if (!sessionState.isSignedIn) {
1228
+ setUser(null);
1229
+ return;
1230
+ }
1231
+ if (user) return;
1232
+ void (async () => {
1233
+ const token = await session.getToken().catch(() => null);
1234
+ if (cancelled || !token) return;
1235
+ try {
1236
+ const fetched = await fetchUser(token);
1237
+ if (!cancelled) setUser(fetched);
1238
+ } catch {
1239
+ }
1240
+ })();
1241
+ return () => {
1242
+ cancelled = true;
1243
+ };
1244
+ }, [sessionState.isSignedIn, user, session, fetchUser]);
1245
+ const contextValue = (0, import_react.useMemo)(() => ({
1246
+ ...state,
1247
+ signIn,
1248
+ signInWithRedirect,
1249
+ signInWithSocial,
1250
+ signUp,
1251
+ signOut,
1252
+ getToken,
1253
+ handleCallback,
1254
+ sendMagicLink,
1255
+ checkEmail,
1256
+ authStrategy,
1257
+ config: {
1258
+ domain,
1259
+ orgId,
1260
+ clientId,
1261
+ redirectUri: resolvedRedirectUri,
1262
+ afterSignInUrl,
1263
+ afterSignUpUrl,
1264
+ afterSignOutUrl
1265
+ }
1266
+ }), [state, signIn, signInWithRedirect, signInWithSocial, signUp, signOut, getToken, handleCallback, sendMagicLink, checkEmail, authStrategy, domain, orgId, clientId, resolvedRedirectUri, afterSignInUrl, afterSignUpUrl, afterSignOutUrl]);
1267
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LumoAuthContext.Provider, { value: contextValue, children });
1268
+ }
1269
+
1270
+ // src/components/SignIn.tsx
1271
+ var import_react2 = require("react");
1272
+
1273
+ // src/utils/url.ts
1274
+ function sanitizeRedirectUrl(url, defaultUrl = "/") {
1275
+ if (!url || typeof url !== "string") {
1276
+ return defaultUrl;
1277
+ }
1278
+ let sanitizedUrl = url.trim().replace(/[\x00-\x1F\x7F]/g, "");
1279
+ try {
1280
+ const parsedUrl = new URL(sanitizedUrl, typeof window !== "undefined" ? window.location.origin : "http://localhost");
1281
+ if (sanitizedUrl.startsWith("/") && !sanitizedUrl.startsWith("//")) {
1282
+ return sanitizedUrl;
1283
+ }
1284
+ const dangerousSchemes = ["javascript:", "data:", "vbscript:", "file:"];
1285
+ if (dangerousSchemes.includes(parsedUrl.protocol.toLowerCase())) {
1286
+ return defaultUrl;
1287
+ }
1288
+ if (typeof window !== "undefined" && parsedUrl.origin !== window.location.origin) {
1289
+ return defaultUrl;
1290
+ }
1291
+ return parsedUrl.href;
1292
+ } catch {
1293
+ return defaultUrl;
1294
+ }
1295
+ }
1296
+
1297
+ // src/components/SignIn.tsx
1298
+ var import_jsx_runtime2 = require("react/jsx-runtime");
1299
+ var SOCIAL_ICONS = {
1300
+ google: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("svg", { className: "la-social-icon", viewBox: "0 0 24 24", fill: "none", children: [
1301
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 0 1-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z", fill: "#4285F4" }),
1302
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z", fill: "#34A853" }),
1303
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z", fill: "#FBBC05" }),
1304
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z", fill: "#EA4335" })
1305
+ ] }),
1306
+ github: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { className: "la-social-icon", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0 0 24 12c0-6.63-5.37-12-12-12z" }) }),
1307
+ microsoft: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("svg", { className: "la-social-icon", viewBox: "0 0 24 24", fill: "none", children: [
1308
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("rect", { x: "1", y: "1", width: "10", height: "10", fill: "#F25022" }),
1309
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("rect", { x: "13", y: "1", width: "10", height: "10", fill: "#7FBA00" }),
1310
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("rect", { x: "1", y: "13", width: "10", height: "10", fill: "#00A4EF" }),
1311
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("rect", { x: "13", y: "13", width: "10", height: "10", fill: "#FFB900" })
1312
+ ] }),
1313
+ apple: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { className: "la-social-icon", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M17.05 20.28c-.98.95-2.05.88-3.08.4-1.09-.5-2.08-.48-3.24 0-1.44.62-2.2.44-3.06-.4C2.79 15.25 3.51 7.59 9.05 7.31c1.35.07 2.29.74 3.08.8 1.18-.24 2.31-.93 3.57-.84 1.51.12 2.65.72 3.4 1.8-3.12 1.87-2.38 5.98.48 7.13-.57 1.5-1.31 2.99-2.54 4.09zM12.03 7.25c-.15-2.23 1.66-4.07 3.74-4.25.29 2.58-2.34 4.5-3.74 4.25z" }) })
1314
+ };
1315
+ function getSocialLabel(provider) {
1316
+ const names = {
1317
+ google: "Google",
1318
+ github: "GitHub",
1319
+ microsoft: "Microsoft",
1320
+ apple: "Apple",
1321
+ facebook: "Facebook",
1322
+ linkedin: "LinkedIn",
1323
+ twitter: "X (Twitter)",
1324
+ gitlab: "GitLab"
1325
+ };
1326
+ return names[provider] || provider.charAt(0).toUpperCase() + provider.slice(1);
1327
+ }
1328
+ function SignIn({
1329
+ afterSignInUrl,
1330
+ signUpUrl,
1331
+ appearance,
1332
+ socialProviders = []
1333
+ }) {
1334
+ const { signIn, signInWithSocial, config, status, authStrategy } = useLumoAuthContext();
1335
+ const resolvedAfterSignInUrl = afterSignInUrl || config.afterSignInUrl || "/";
1336
+ const resolvedSignUpUrl = signUpUrl || config.afterSignUpUrl || "/sign-up";
1337
+ const themeClass = appearance?.theme === "dark" ? "la-dark" : appearance?.theme === "light" ? "la-light" : "";
1338
+ if (status === "authenticated") {
1339
+ return null;
1340
+ }
1341
+ if (authStrategy === "pkce") {
1342
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1343
+ SignInPkce,
1344
+ {
1345
+ signIn,
1346
+ signInWithSocial,
1347
+ socialProviders,
1348
+ resolvedSignUpUrl,
1349
+ themeClass,
1350
+ appearance
1351
+ }
1352
+ );
1353
+ }
1354
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1355
+ SignInPassword,
1356
+ {
1357
+ signIn,
1358
+ signInWithSocial,
1359
+ socialProviders,
1360
+ config,
1361
+ resolvedAfterSignInUrl,
1362
+ resolvedSignUpUrl,
1363
+ themeClass,
1364
+ appearance
1365
+ }
1366
+ );
1367
+ }
1368
+ function SignInPkce({
1369
+ signIn,
1370
+ signInWithSocial,
1371
+ socialProviders,
1372
+ resolvedSignUpUrl,
1373
+ themeClass,
1374
+ appearance
1375
+ }) {
1376
+ const handleSocialLogin = (0, import_react2.useCallback)((provider) => {
1377
+ signInWithSocial(provider);
1378
+ }, [signInWithSocial]);
1379
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1380
+ "div",
1381
+ {
1382
+ className: `la-card ${themeClass} ${appearance?.className || ""}`,
1383
+ style: appearance?.variables,
1384
+ children: [
1385
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "la-card-header", children: [
1386
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h2", { className: "la-card-title", children: "Sign in" }),
1387
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "la-card-subtitle", children: "Welcome back! Please sign in to continue." })
1388
+ ] }),
1389
+ socialProviders.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "la-social-buttons", children: socialProviders.map((provider) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1390
+ "button",
1391
+ {
1392
+ type: "button",
1393
+ className: "la-social-btn",
1394
+ onClick: () => handleSocialLogin(provider),
1395
+ children: [
1396
+ SOCIAL_ICONS[provider] || null,
1397
+ "Continue with ",
1398
+ getSocialLabel(provider)
1399
+ ]
1400
+ },
1401
+ provider
1402
+ )) }),
1403
+ socialProviders.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "la-divider", children: "or" }),
1404
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1405
+ "button",
1406
+ {
1407
+ type: "button",
1408
+ className: "la-btn la-btn-primary",
1409
+ onClick: () => signIn(),
1410
+ children: "Sign in with email"
1411
+ }
1412
+ ),
1413
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "la-footer", children: [
1414
+ "Don't have an account?",
1415
+ " ",
1416
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", { href: resolvedSignUpUrl, children: "Sign up" })
1417
+ ] })
1418
+ ]
1419
+ }
1420
+ );
1421
+ }
1422
+ function SignInPassword({
1423
+ signIn,
1424
+ signInWithSocial,
1425
+ socialProviders,
1426
+ config,
1427
+ resolvedAfterSignInUrl,
1428
+ resolvedSignUpUrl,
1429
+ themeClass,
1430
+ appearance
1431
+ }) {
1432
+ const [email, setEmail] = (0, import_react2.useState)("");
1433
+ const [password, setPassword] = (0, import_react2.useState)("");
1434
+ const [error, setError] = (0, import_react2.useState)(null);
1435
+ const [loading, setLoading] = (0, import_react2.useState)(false);
1436
+ const handleSubmit = (0, import_react2.useCallback)(async (e) => {
1437
+ e.preventDefault();
1438
+ setError(null);
1439
+ setLoading(true);
1440
+ try {
1441
+ await signIn(email, password);
1442
+ if (typeof window !== "undefined") {
1443
+ window.location.href = sanitizeRedirectUrl(resolvedAfterSignInUrl);
1444
+ }
1445
+ } catch (err) {
1446
+ setError(err instanceof Error ? err.message : "Sign in failed. Please try again.");
1447
+ } finally {
1448
+ setLoading(false);
1449
+ }
1450
+ }, [signIn, email, password, resolvedAfterSignInUrl]);
1451
+ const handleSocialLogin = (0, import_react2.useCallback)((provider) => {
1452
+ signInWithSocial(provider);
1453
+ }, [signInWithSocial]);
1454
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1455
+ "div",
1456
+ {
1457
+ className: `la-card ${themeClass} ${appearance?.className || ""}`,
1458
+ style: appearance?.variables,
1459
+ children: [
1460
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "la-card-header", children: [
1461
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h2", { className: "la-card-title", children: "Sign in" }),
1462
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "la-card-subtitle", children: "Welcome back! Please sign in to continue." })
1463
+ ] }),
1464
+ socialProviders.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "la-social-buttons", children: socialProviders.map((provider) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1465
+ "button",
1466
+ {
1467
+ type: "button",
1468
+ className: "la-social-btn",
1469
+ onClick: () => handleSocialLogin(provider),
1470
+ disabled: loading,
1471
+ children: [
1472
+ SOCIAL_ICONS[provider] || null,
1473
+ "Continue with ",
1474
+ getSocialLabel(provider)
1475
+ ]
1476
+ },
1477
+ provider
1478
+ )) }),
1479
+ socialProviders.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "la-divider", children: "or" }),
1480
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("form", { onSubmit: handleSubmit, children: [
1481
+ error && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "la-alert la-alert-error", role: "alert", children: error }),
1482
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "la-form-group", children: [
1483
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { className: "la-label", htmlFor: "la-signin-email", children: "Email address" }),
1484
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1485
+ "input",
1486
+ {
1487
+ id: "la-signin-email",
1488
+ className: "la-input",
1489
+ type: "email",
1490
+ placeholder: "name@example.com",
1491
+ value: email,
1492
+ onChange: (e) => setEmail(e.target.value),
1493
+ required: true,
1494
+ autoComplete: "email",
1495
+ disabled: loading
1496
+ }
1497
+ )
1498
+ ] }),
1499
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "la-form-group", children: [
1500
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { className: "la-label", htmlFor: "la-signin-password", children: "Password" }),
1501
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1502
+ "input",
1503
+ {
1504
+ id: "la-signin-password",
1505
+ className: "la-input",
1506
+ type: "password",
1507
+ placeholder: "Enter your password",
1508
+ value: password,
1509
+ onChange: (e) => setPassword(e.target.value),
1510
+ required: true,
1511
+ autoComplete: "current-password",
1512
+ disabled: loading
1513
+ }
1514
+ )
1515
+ ] }),
1516
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "la-forgot", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", { href: `${config.domain}/account/forgot-password`, children: "Forgot password?" }) }),
1517
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1518
+ "button",
1519
+ {
1520
+ type: "submit",
1521
+ className: "la-btn la-btn-primary",
1522
+ disabled: loading || !email || !password,
1523
+ children: [
1524
+ loading ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "la-spinner la-spinner-sm" }) : null,
1525
+ loading ? "Signing in\u2026" : "Sign in"
1526
+ ]
1527
+ }
1528
+ )
1529
+ ] }),
1530
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "la-footer", children: [
1531
+ "Don't have an account?",
1532
+ " ",
1533
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", { href: resolvedSignUpUrl, children: "Sign up" })
1534
+ ] })
1535
+ ]
1536
+ }
1537
+ );
1538
+ }
1539
+
1540
+ // src/components/SignUp.tsx
1541
+ var import_react3 = require("react");
1542
+ var import_jsx_runtime3 = require("react/jsx-runtime");
1543
+ function getPasswordStrength(password) {
1544
+ if (!password) return { score: 0, label: "" };
1545
+ let score = 0;
1546
+ if (password.length >= 8) score++;
1547
+ if (password.length >= 12) score++;
1548
+ if (/[A-Z]/.test(password) && /[a-z]/.test(password)) score++;
1549
+ if (/\d/.test(password)) score++;
1550
+ if (/[^A-Za-z0-9]/.test(password)) score++;
1551
+ const capped = Math.min(score, 4);
1552
+ const labels = ["", "Weak", "Fair", "Good", "Strong"];
1553
+ return { score: capped, label: labels[capped] };
1554
+ }
1555
+ function SignUp({
1556
+ afterSignUpUrl,
1557
+ signInUrl,
1558
+ appearance
1559
+ }) {
1560
+ const { signUp, config, status, authStrategy } = useLumoAuthContext();
1561
+ const resolvedSignInUrl = signInUrl || "/sign-in";
1562
+ const themeClass = appearance?.theme === "dark" ? "la-dark" : appearance?.theme === "light" ? "la-light" : "";
1563
+ if (status === "authenticated") {
1564
+ return null;
1565
+ }
1566
+ if (authStrategy === "pkce") {
1567
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1568
+ "div",
1569
+ {
1570
+ className: `la-card ${themeClass} ${appearance?.className || ""}`,
1571
+ style: appearance?.variables,
1572
+ children: [
1573
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "la-card-header", children: [
1574
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h2", { className: "la-card-title", children: "Create your account" }),
1575
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "la-card-subtitle", children: "Get started \u2014 it only takes a minute." })
1576
+ ] }),
1577
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1578
+ "button",
1579
+ {
1580
+ type: "button",
1581
+ className: "la-btn la-btn-primary",
1582
+ onClick: () => signUp({ email: "", password: "" }),
1583
+ children: "Create account"
1584
+ }
1585
+ ),
1586
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "la-footer", children: [
1587
+ "Already have an account?",
1588
+ " ",
1589
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("a", { href: resolvedSignInUrl, children: "Sign in" })
1590
+ ] })
1591
+ ]
1592
+ }
1593
+ );
1594
+ }
1595
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1596
+ SignUpPasswordForm,
1597
+ {
1598
+ signUp,
1599
+ resolvedAfterSignUpUrl: afterSignUpUrl || config.afterSignUpUrl || "/",
1600
+ resolvedSignInUrl,
1601
+ themeClass,
1602
+ appearance
1603
+ }
1604
+ );
1605
+ }
1606
+ function SignUpPasswordForm({
1607
+ signUp,
1608
+ resolvedAfterSignUpUrl,
1609
+ resolvedSignInUrl,
1610
+ themeClass,
1611
+ appearance
1612
+ }) {
1613
+ const [firstName, setFirstName] = (0, import_react3.useState)("");
1614
+ const [lastName, setLastName] = (0, import_react3.useState)("");
1615
+ const [email, setEmail] = (0, import_react3.useState)("");
1616
+ const [password, setPassword] = (0, import_react3.useState)("");
1617
+ const [error, setError] = (0, import_react3.useState)(null);
1618
+ const [loading, setLoading] = (0, import_react3.useState)(false);
1619
+ const passwordStrength = (0, import_react3.useMemo)(() => getPasswordStrength(password), [password]);
1620
+ const handleSubmit = (0, import_react3.useCallback)(async (e) => {
1621
+ e.preventDefault();
1622
+ setError(null);
1623
+ setLoading(true);
1624
+ try {
1625
+ await signUp({
1626
+ email,
1627
+ password,
1628
+ firstName: firstName || void 0,
1629
+ lastName: lastName || void 0
1630
+ });
1631
+ if (typeof window !== "undefined") {
1632
+ window.location.href = sanitizeRedirectUrl(resolvedAfterSignUpUrl);
1633
+ }
1634
+ } catch (err) {
1635
+ setError(err instanceof Error ? err.message : "Registration failed. Please try again.");
1636
+ } finally {
1637
+ setLoading(false);
1638
+ }
1639
+ }, [signUp, email, password, firstName, lastName, resolvedAfterSignUpUrl]);
1640
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1641
+ "div",
1642
+ {
1643
+ className: `la-card ${themeClass} ${appearance?.className || ""}`,
1644
+ style: appearance?.variables,
1645
+ children: [
1646
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "la-card-header", children: [
1647
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h2", { className: "la-card-title", children: "Create your account" }),
1648
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "la-card-subtitle", children: "Get started \u2014 it only takes a minute." })
1649
+ ] }),
1650
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("form", { onSubmit: handleSubmit, children: [
1651
+ error && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "la-alert la-alert-error", role: "alert", children: error }),
1652
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "flex", gap: "0.75rem" }, children: [
1653
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "la-form-group", style: { flex: 1 }, children: [
1654
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("label", { className: "la-label", htmlFor: "la-signup-firstname", children: "First name" }),
1655
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1656
+ "input",
1657
+ {
1658
+ id: "la-signup-firstname",
1659
+ className: "la-input",
1660
+ type: "text",
1661
+ placeholder: "Jane",
1662
+ value: firstName,
1663
+ onChange: (e) => setFirstName(e.target.value),
1664
+ autoComplete: "given-name",
1665
+ disabled: loading
1666
+ }
1667
+ )
1668
+ ] }),
1669
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "la-form-group", style: { flex: 1 }, children: [
1670
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("label", { className: "la-label", htmlFor: "la-signup-lastname", children: "Last name" }),
1671
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1672
+ "input",
1673
+ {
1674
+ id: "la-signup-lastname",
1675
+ className: "la-input",
1676
+ type: "text",
1677
+ placeholder: "Doe",
1678
+ value: lastName,
1679
+ onChange: (e) => setLastName(e.target.value),
1680
+ autoComplete: "family-name",
1681
+ disabled: loading
1682
+ }
1683
+ )
1684
+ ] })
1685
+ ] }),
1686
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "la-form-group", children: [
1687
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("label", { className: "la-label", htmlFor: "la-signup-email", children: "Email address" }),
1688
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1689
+ "input",
1690
+ {
1691
+ id: "la-signup-email",
1692
+ className: "la-input",
1693
+ type: "email",
1694
+ placeholder: "name@example.com",
1695
+ value: email,
1696
+ onChange: (e) => setEmail(e.target.value),
1697
+ required: true,
1698
+ autoComplete: "email",
1699
+ disabled: loading
1700
+ }
1701
+ )
1702
+ ] }),
1703
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "la-form-group", children: [
1704
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("label", { className: "la-label", htmlFor: "la-signup-password", children: "Password" }),
1705
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1706
+ "input",
1707
+ {
1708
+ id: "la-signup-password",
1709
+ className: "la-input",
1710
+ type: "password",
1711
+ placeholder: "Create a strong password",
1712
+ value: password,
1713
+ onChange: (e) => setPassword(e.target.value),
1714
+ required: true,
1715
+ minLength: 8,
1716
+ autoComplete: "new-password",
1717
+ disabled: loading
1718
+ }
1719
+ ),
1720
+ password && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "la-password-strength", children: [
1721
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "la-password-bar", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1722
+ "div",
1723
+ {
1724
+ className: "la-password-fill",
1725
+ "data-strength": passwordStrength.score
1726
+ }
1727
+ ) }),
1728
+ passwordStrength.label && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "la-password-label", children: passwordStrength.label })
1729
+ ] })
1730
+ ] }),
1731
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1732
+ "button",
1733
+ {
1734
+ type: "submit",
1735
+ className: "la-btn la-btn-primary",
1736
+ disabled: loading || !email || !password,
1737
+ style: { marginTop: "0.5rem" },
1738
+ children: [
1739
+ loading ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "la-spinner la-spinner-sm" }) : null,
1740
+ loading ? "Creating account\u2026" : "Create account"
1741
+ ]
1742
+ }
1743
+ )
1744
+ ] }),
1745
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "la-footer", children: [
1746
+ "Already have an account?",
1747
+ " ",
1748
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("a", { href: resolvedSignInUrl, children: "Sign in" })
1749
+ ] })
1750
+ ]
1751
+ }
1752
+ );
1753
+ }
1754
+
1755
+ // src/components/AuthCallback.tsx
1756
+ var import_react4 = require("react");
1757
+ var import_jsx_runtime4 = require("react/jsx-runtime");
1758
+ function AuthCallback({
1759
+ afterSignInUrl,
1760
+ loading,
1761
+ error: errorComponent
1762
+ }) {
1763
+ const { handleCallback, config } = useLumoAuthContext();
1764
+ const [error, setError] = (0, import_react4.useState)(null);
1765
+ const resolvedAfterSignInUrl = afterSignInUrl || config.afterSignInUrl || "/";
1766
+ (0, import_react4.useEffect)(() => {
1767
+ let cancelled = false;
1768
+ handleCallback().then(() => {
1769
+ if (!cancelled && typeof window !== "undefined") {
1770
+ window.location.href = sanitizeRedirectUrl(resolvedAfterSignInUrl);
1771
+ }
1772
+ }).catch((err) => {
1773
+ if (!cancelled) {
1774
+ setError(err instanceof Error ? err.message : "Authentication failed");
1775
+ }
1776
+ });
1777
+ return () => {
1778
+ cancelled = true;
1779
+ };
1780
+ }, [handleCallback, resolvedAfterSignInUrl]);
1781
+ if (error) {
1782
+ if (errorComponent) {
1783
+ return typeof errorComponent === "function" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children: errorComponent(error) }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children: errorComponent });
1784
+ }
1785
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "la-card", children: [
1786
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "la-card-header", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h2", { className: "la-card-title", children: "Authentication Error" }) }),
1787
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "la-alert la-alert-error", role: "alert", children: error }),
1788
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1789
+ "button",
1790
+ {
1791
+ type: "button",
1792
+ className: "la-btn la-btn-primary",
1793
+ onClick: () => {
1794
+ if (typeof window !== "undefined") {
1795
+ window.location.href = "/";
1796
+ }
1797
+ },
1798
+ children: "Return home"
1799
+ }
1800
+ )
1801
+ ] });
1802
+ }
1803
+ if (loading) {
1804
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children: loading });
1805
+ }
1806
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "la-card", style: { textAlign: "center" }, children: [
1807
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "la-spinner" }),
1808
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: { marginTop: "1rem", color: "var(--la-text-secondary)" }, children: "Completing sign-in\u2026" })
1809
+ ] });
1810
+ }
1811
+
1812
+ // src/components/UserButton.tsx
1813
+ var import_react5 = require("react");
1814
+ var import_jsx_runtime5 = require("react/jsx-runtime");
1815
+ function UserButton({
1816
+ afterSignOutUrl,
1817
+ showName = false,
1818
+ appearance
1819
+ }) {
1820
+ const { user, isSignedIn, signOut, config } = useLumoAuthContext();
1821
+ const [isOpen, setIsOpen] = (0, import_react5.useState)(false);
1822
+ const containerRef = (0, import_react5.useRef)(null);
1823
+ const resolvedSignOutUrl = afterSignOutUrl || config.afterSignOutUrl || "/";
1824
+ (0, import_react5.useEffect)(() => {
1825
+ function handleClickOutside(e) {
1826
+ if (containerRef.current && !containerRef.current.contains(e.target)) {
1827
+ setIsOpen(false);
1828
+ }
1829
+ }
1830
+ if (isOpen) {
1831
+ document.addEventListener("mousedown", handleClickOutside);
1832
+ return () => document.removeEventListener("mousedown", handleClickOutside);
1833
+ }
1834
+ }, [isOpen]);
1835
+ (0, import_react5.useEffect)(() => {
1836
+ function handleEscape(e) {
1837
+ if (e.key === "Escape") setIsOpen(false);
1838
+ }
1839
+ if (isOpen) {
1840
+ document.addEventListener("keydown", handleEscape);
1841
+ return () => document.removeEventListener("keydown", handleEscape);
1842
+ }
1843
+ }, [isOpen]);
1844
+ const handleSignOut = (0, import_react5.useCallback)(async () => {
1845
+ setIsOpen(false);
1846
+ await signOut({ afterSignOutUrl: sanitizeRedirectUrl(resolvedSignOutUrl) });
1847
+ }, [signOut, resolvedSignOutUrl]);
1848
+ if (!isSignedIn || !user) {
1849
+ return null;
1850
+ }
1851
+ const initials = [user.firstName, user.lastName].filter(Boolean).map((n) => n.charAt(0).toUpperCase()).join("") || user.email.charAt(0).toUpperCase();
1852
+ const themeClass = appearance?.theme === "dark" ? "la-dark" : appearance?.theme === "light" ? "la-light" : "";
1853
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1854
+ "div",
1855
+ {
1856
+ ref: containerRef,
1857
+ className: `la-user-button ${themeClass} ${appearance?.className || ""}`,
1858
+ style: appearance?.variables,
1859
+ children: [
1860
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1861
+ "button",
1862
+ {
1863
+ type: "button",
1864
+ className: "la-user-trigger",
1865
+ onClick: () => setIsOpen(!isOpen),
1866
+ "aria-expanded": isOpen,
1867
+ "aria-haspopup": "menu",
1868
+ "aria-label": "User menu",
1869
+ children: [
1870
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "la-user-avatar", children: user.avatarUrl ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("img", { src: user.avatarUrl, alt: user.displayName }) : initials }),
1871
+ showName && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "la-user-name", children: user.displayName })
1872
+ ]
1873
+ }
1874
+ ),
1875
+ isOpen && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "la-user-dropdown", role: "menu", children: [
1876
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "la-user-dropdown-header", children: [
1877
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "la-user-dropdown-name", children: user.displayName }),
1878
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "la-user-dropdown-email", children: user.email })
1879
+ ] }),
1880
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1881
+ "button",
1882
+ {
1883
+ type: "button",
1884
+ className: "la-dropdown-item",
1885
+ role: "menuitem",
1886
+ onClick: () => {
1887
+ setIsOpen(false);
1888
+ window.location.href = `${config.domain}/account/profile`;
1889
+ },
1890
+ children: [
1891
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
1892
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("path", { d: "M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2" }),
1893
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("circle", { cx: "12", cy: "7", r: "4" })
1894
+ ] }),
1895
+ "Manage account"
1896
+ ]
1897
+ }
1898
+ ),
1899
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "la-dropdown-divider" }),
1900
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1901
+ "button",
1902
+ {
1903
+ type: "button",
1904
+ className: "la-dropdown-item la-dropdown-item-danger",
1905
+ role: "menuitem",
1906
+ onClick: handleSignOut,
1907
+ children: [
1908
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
1909
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("path", { d: "M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4" }),
1910
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("polyline", { points: "16 17 21 12 16 7" }),
1911
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("line", { x1: "21", y1: "12", x2: "9", y2: "12" })
1912
+ ] }),
1913
+ "Sign out"
1914
+ ]
1915
+ }
1916
+ )
1917
+ ] })
1918
+ ]
1919
+ }
1920
+ );
1921
+ }
1922
+
1923
+ // src/components/UserAvatar.tsx
1924
+ var import_jsx_runtime6 = require("react/jsx-runtime");
1925
+ function UserAvatar({
1926
+ size = 32,
1927
+ shape = "circle",
1928
+ appearance
1929
+ }) {
1930
+ const { user, isSignedIn } = useLumoAuthContext();
1931
+ if (!isSignedIn || !user) {
1932
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1933
+ "span",
1934
+ {
1935
+ className: `la-avatar la-avatar-${shape} ${appearance?.className || ""}`,
1936
+ style: {
1937
+ width: size,
1938
+ height: size,
1939
+ fontSize: size * 0.4,
1940
+ ...appearance?.variables
1941
+ },
1942
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", width: size * 0.5, height: size * 0.5, children: [
1943
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("path", { d: "M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2" }),
1944
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("circle", { cx: "12", cy: "7", r: "4" })
1945
+ ] })
1946
+ }
1947
+ );
1948
+ }
1949
+ const initials = [user.firstName, user.lastName].filter(Boolean).map((n) => n.charAt(0).toUpperCase()).join("") || user.email.charAt(0).toUpperCase();
1950
+ const themeClass = appearance?.theme === "dark" ? "la-dark" : appearance?.theme === "light" ? "la-light" : "";
1951
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1952
+ "span",
1953
+ {
1954
+ className: `la-avatar la-avatar-${shape} ${themeClass} ${appearance?.className || ""}`,
1955
+ style: {
1956
+ width: size,
1957
+ height: size,
1958
+ fontSize: size * 0.4,
1959
+ ...appearance?.variables
1960
+ },
1961
+ title: user.displayName,
1962
+ children: user.avatarUrl ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1963
+ "img",
1964
+ {
1965
+ src: user.avatarUrl,
1966
+ alt: user.displayName,
1967
+ style: { width: "100%", height: "100%", objectFit: "cover" }
1968
+ }
1969
+ ) : initials
1970
+ }
1971
+ );
1972
+ }
1973
+
1974
+ // src/components/UserProfile.tsx
1975
+ var import_react6 = require("react");
1976
+ var import_jsx_runtime7 = require("react/jsx-runtime");
1977
+ var ICONS = {
1978
+ user: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
1979
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("path", { d: "M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2" }),
1980
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("circle", { cx: "12", cy: "7", r: "4" })
1981
+ ] }),
1982
+ mail: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
1983
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("rect", { x: "2", y: "4", width: "20", height: "16", rx: "2" }),
1984
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("path", { d: "m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7" })
1985
+ ] }),
1986
+ shield: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("path", { d: "M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z" }) }),
1987
+ key: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("path", { d: "m21 2-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0 3 3L22 7l-3-3m-3.5 3.5L19 4" }) }),
1988
+ check: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "3", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("polyline", { points: "20 6 9 17 4 12" }) }),
1989
+ x: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "3", strokeLinecap: "round", strokeLinejoin: "round", children: [
1990
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
1991
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
1992
+ ] }),
1993
+ signOut: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
1994
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("path", { d: "M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4" }),
1995
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("polyline", { points: "16 17 21 12 16 7" }),
1996
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("line", { x1: "21", y1: "12", x2: "9", y2: "12" })
1997
+ ] })
1998
+ };
1999
+ function UserProfile({
2000
+ afterSignOutUrl,
2001
+ mode = "full",
2002
+ appearance
2003
+ }) {
2004
+ const { user, isSignedIn, isLoaded, signOut, config } = useLumoAuthContext();
2005
+ const [signingOut, setSigningOut] = (0, import_react6.useState)(false);
2006
+ const resolvedSignOutUrl = afterSignOutUrl || config.afterSignOutUrl || "/";
2007
+ const handleSignOut = (0, import_react6.useCallback)(async () => {
2008
+ setSigningOut(true);
2009
+ await signOut({ afterSignOutUrl: resolvedSignOutUrl });
2010
+ }, [signOut, resolvedSignOutUrl]);
2011
+ if (!isLoaded) {
2012
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "la-card", style: { textAlign: "center", padding: "2rem" }, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "la-spinner" }) });
2013
+ }
2014
+ if (!isSignedIn || !user) {
2015
+ return null;
2016
+ }
2017
+ const initials = [user.firstName, user.lastName].filter(Boolean).map((n) => n.charAt(0).toUpperCase()).join("") || user.email.charAt(0).toUpperCase();
2018
+ const themeClass = appearance?.theme === "dark" ? "la-dark" : appearance?.theme === "light" ? "la-light" : "";
2019
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
2020
+ "div",
2021
+ {
2022
+ className: `la-card la-profile-card ${themeClass} ${appearance?.className || ""}`,
2023
+ style: appearance?.variables,
2024
+ children: [
2025
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "la-profile-header", children: [
2026
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "la-avatar la-avatar-circle la-profile-avatar", children: user.avatarUrl ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("img", { src: user.avatarUrl, alt: user.displayName }) : initials }),
2027
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "la-profile-header-info", children: [
2028
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "la-profile-name", children: user.displayName }),
2029
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "la-profile-email", children: user.email })
2030
+ ] })
2031
+ ] }),
2032
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "la-profile-section", children: [
2033
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "la-profile-section-title", children: "Account" }),
2034
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "la-profile-row", children: [
2035
+ ICONS.mail,
2036
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "la-profile-row-label", children: "Email" }),
2037
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "la-profile-row-value", children: user.email }),
2038
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: `la-profile-badge ${user.emailVerified ? "la-badge-success" : "la-badge-warning"}`, children: [
2039
+ user.emailVerified ? ICONS.check : ICONS.x,
2040
+ user.emailVerified ? "Verified" : "Unverified"
2041
+ ] })
2042
+ ] }),
2043
+ user.firstName && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "la-profile-row", children: [
2044
+ ICONS.user,
2045
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "la-profile-row-label", children: "Name" }),
2046
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "la-profile-row-value", children: [user.firstName, user.lastName].filter(Boolean).join(" ") })
2047
+ ] })
2048
+ ] }),
2049
+ mode === "full" && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
2050
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "la-profile-section", children: [
2051
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "la-profile-section-title", children: "Security" }),
2052
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "la-profile-row", children: [
2053
+ ICONS.shield,
2054
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "la-profile-row-label", children: "MFA" }),
2055
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: `la-profile-badge ${user.mfaEnabled ? "la-badge-success" : "la-badge-muted"}`, children: [
2056
+ user.mfaEnabled ? ICONS.check : ICONS.x,
2057
+ user.mfaEnabled ? "Enabled" : "Disabled"
2058
+ ] })
2059
+ ] })
2060
+ ] }),
2061
+ (user.roles.length > 0 || user.groups.length > 0) && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "la-profile-section", children: [
2062
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "la-profile-section-title", children: "Roles & Groups" }),
2063
+ user.roles.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "la-profile-row", children: [
2064
+ ICONS.key,
2065
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "la-profile-row-label", children: "Roles" }),
2066
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "la-profile-tags", children: user.roles.map((role) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "la-profile-tag", children: role }, role)) })
2067
+ ] }),
2068
+ user.groups.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "la-profile-row", children: [
2069
+ ICONS.user,
2070
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "la-profile-row-label", children: "Groups" }),
2071
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "la-profile-tags", children: user.groups.map((group) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "la-profile-tag", children: group }, group)) })
2072
+ ] })
2073
+ ] })
2074
+ ] }),
2075
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "la-profile-section la-profile-actions", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
2076
+ "button",
2077
+ {
2078
+ type: "button",
2079
+ className: "la-btn la-btn-outline la-profile-signout-btn",
2080
+ onClick: handleSignOut,
2081
+ disabled: signingOut,
2082
+ children: [
2083
+ signingOut ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "la-spinner la-spinner-sm" }) : ICONS.signOut,
2084
+ signingOut ? "Signing out\u2026" : "Sign out"
2085
+ ]
2086
+ }
2087
+ ) })
2088
+ ]
2089
+ }
2090
+ );
2091
+ }
2092
+
2093
+ // src/hooks.ts
2094
+ var import_react7 = require("react");
2095
+ var import_client3 = require("@lumoauth/client");
2096
+ function useAuth() {
2097
+ return useLumoAuthContext();
2098
+ }
2099
+ function useUser() {
2100
+ const { user } = useLumoAuthContext();
2101
+ return user;
2102
+ }
2103
+ function useSignIn() {
2104
+ const { signIn, signInWithRedirect, status } = useLumoAuthContext();
2105
+ return {
2106
+ signIn,
2107
+ signInWithRedirect,
2108
+ isLoading: status === "loading"
2109
+ };
2110
+ }
2111
+ function useSession() {
2112
+ const { isSignedIn, isLoaded, getToken, status } = useLumoAuthContext();
2113
+ return {
2114
+ isActive: isSignedIn,
2115
+ isLoaded,
2116
+ getToken,
2117
+ status
2118
+ };
2119
+ }
2120
+ function useLumoAuth() {
2121
+ const { getToken, config } = useLumoAuthContext();
2122
+ const client = (0, import_react7.useMemo)(
2123
+ () => new import_client3.LumoAuth({
2124
+ baseUrl: config.domain,
2125
+ orgId: config.orgId,
2126
+ clientId: config.clientId,
2127
+ token: () => getToken().then((t) => t || "")
2128
+ }),
2129
+ [config.domain, config.orgId, config.clientId, getToken]
2130
+ );
2131
+ return client;
2132
+ }
2133
+ function usePermission(slug) {
2134
+ const client = useLumoAuth();
2135
+ const { isSignedIn, isLoaded } = useLumoAuthContext();
2136
+ const [allowed, setAllowed] = (0, import_react7.useState)(false);
2137
+ const [isLoading, setIsLoading] = (0, import_react7.useState)(true);
2138
+ (0, import_react7.useEffect)(() => {
2139
+ if (!isLoaded || !isSignedIn) {
2140
+ setAllowed(false);
2141
+ setIsLoading(!isLoaded);
2142
+ return;
2143
+ }
2144
+ let cancelled = false;
2145
+ setIsLoading(true);
2146
+ client.permissions.check(slug).then((result) => {
2147
+ if (!cancelled) {
2148
+ setAllowed(result);
2149
+ setIsLoading(false);
2150
+ }
2151
+ }).catch(() => {
2152
+ if (!cancelled) {
2153
+ setAllowed(false);
2154
+ setIsLoading(false);
2155
+ }
2156
+ });
2157
+ return () => {
2158
+ cancelled = true;
2159
+ };
2160
+ }, [client, slug, isSignedIn, isLoaded]);
2161
+ return { allowed, isLoading };
2162
+ }
2163
+ function useZanzibar(request) {
2164
+ const client = useLumoAuth();
2165
+ const { isSignedIn, isLoaded } = useLumoAuthContext();
2166
+ const [allowed, setAllowed] = (0, import_react7.useState)(false);
2167
+ const [isLoading, setIsLoading] = (0, import_react7.useState)(true);
2168
+ const requestKey = `${request.object}:${request.relation}:${request.subject}`;
2169
+ (0, import_react7.useEffect)(() => {
2170
+ if (!isLoaded || !isSignedIn) {
2171
+ setAllowed(false);
2172
+ setIsLoading(!isLoaded);
2173
+ return;
2174
+ }
2175
+ let cancelled = false;
2176
+ setIsLoading(true);
2177
+ client.zanzibar.check(request).then((result) => {
2178
+ if (!cancelled) {
2179
+ setAllowed(result);
2180
+ setIsLoading(false);
2181
+ }
2182
+ }).catch(() => {
2183
+ if (!cancelled) {
2184
+ setAllowed(false);
2185
+ setIsLoading(false);
2186
+ }
2187
+ });
2188
+ return () => {
2189
+ cancelled = true;
2190
+ };
2191
+ }, [client, requestKey, isSignedIn, isLoaded]);
2192
+ return { allowed, isLoading };
2193
+ }
2194
+ function useAbac(request) {
2195
+ const client = useLumoAuth();
2196
+ const { isSignedIn, isLoaded } = useLumoAuthContext();
2197
+ const [allowed, setAllowed] = (0, import_react7.useState)(false);
2198
+ const [isLoading, setIsLoading] = (0, import_react7.useState)(true);
2199
+ const requestKey = `${request.resourceType}:${request.action}:${request.resourceId || ""}`;
2200
+ (0, import_react7.useEffect)(() => {
2201
+ if (!isLoaded || !isSignedIn) {
2202
+ setAllowed(false);
2203
+ setIsLoading(!isLoaded);
2204
+ return;
2205
+ }
2206
+ let cancelled = false;
2207
+ setIsLoading(true);
2208
+ client.abac.check(request).then((res) => {
2209
+ if (!cancelled) {
2210
+ setAllowed(res.allowed);
2211
+ setIsLoading(false);
2212
+ }
2213
+ }).catch(() => {
2214
+ if (!cancelled) {
2215
+ setAllowed(false);
2216
+ setIsLoading(false);
2217
+ }
2218
+ });
2219
+ return () => {
2220
+ cancelled = true;
2221
+ };
2222
+ }, [client, requestKey, isSignedIn, isLoaded]);
2223
+ return { allowed, isLoading };
2224
+ }
2225
+ function useMagicLink() {
2226
+ const { sendMagicLink: sendMagicLinkCtx } = useLumoAuthContext();
2227
+ const [isLoading, setIsLoading] = (0, import_react7.useState)(false);
2228
+ const [isSent, setIsSent] = (0, import_react7.useState)(false);
2229
+ const [error, setError] = (0, import_react7.useState)(null);
2230
+ const sendMagicLink = (0, import_react7.useCallback)(async (email, redirectUri) => {
2231
+ setIsLoading(true);
2232
+ setError(null);
2233
+ try {
2234
+ await sendMagicLinkCtx(email, redirectUri);
2235
+ setIsSent(true);
2236
+ } catch (err) {
2237
+ setError(err instanceof Error ? err.message : "Failed to send magic link");
2238
+ } finally {
2239
+ setIsLoading(false);
2240
+ }
2241
+ }, [sendMagicLinkCtx]);
2242
+ const reset = (0, import_react7.useCallback)(() => {
2243
+ setIsSent(false);
2244
+ setError(null);
2245
+ setIsLoading(false);
2246
+ }, []);
2247
+ return { sendMagicLink, isLoading, isSent, error, reset };
2248
+ }
2249
+ function useEmailFirst() {
2250
+ const { checkEmail: checkEmailCtx } = useLumoAuthContext();
2251
+ const [isLoading, setIsLoading] = (0, import_react7.useState)(false);
2252
+ const [result, setResult] = (0, import_react7.useState)(null);
2253
+ const checkEmail = (0, import_react7.useCallback)(async (email) => {
2254
+ setIsLoading(true);
2255
+ try {
2256
+ const res = await checkEmailCtx(email);
2257
+ setResult(res);
2258
+ return res;
2259
+ } finally {
2260
+ setIsLoading(false);
2261
+ }
2262
+ }, [checkEmailCtx]);
2263
+ const reset = (0, import_react7.useCallback)(() => {
2264
+ setResult(null);
2265
+ setIsLoading(false);
2266
+ }, []);
2267
+ return { checkEmail, isLoading, result, exists: result?.exists ?? null, reset };
2268
+ }
2269
+
2270
+ // src/components/Protect.tsx
2271
+ var import_jsx_runtime8 = require("react/jsx-runtime");
2272
+ function Protect({
2273
+ permission,
2274
+ zanzibar,
2275
+ abac,
2276
+ fallback = null,
2277
+ children
2278
+ }) {
2279
+ const { isLoaded, isSignedIn, user } = useLumoAuthContext();
2280
+ if (permission) {
2281
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2282
+ ProtectWithPermission,
2283
+ {
2284
+ permission,
2285
+ fallback,
2286
+ isLoaded,
2287
+ isSignedIn,
2288
+ children
2289
+ }
2290
+ );
2291
+ }
2292
+ if (zanzibar) {
2293
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2294
+ ProtectWithZanzibar,
2295
+ {
2296
+ zanzibar,
2297
+ fallback,
2298
+ isLoaded,
2299
+ isSignedIn,
2300
+ user,
2301
+ children
2302
+ }
2303
+ );
2304
+ }
2305
+ if (abac) {
2306
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2307
+ ProtectWithAbac,
2308
+ {
2309
+ abac,
2310
+ fallback,
2311
+ isLoaded,
2312
+ isSignedIn,
2313
+ children
2314
+ }
2315
+ );
2316
+ }
2317
+ if (!isLoaded) {
2318
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "la-protect-loading", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "la-spinner" }) });
2319
+ }
2320
+ return isSignedIn ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children: fallback });
2321
+ }
2322
+ function ProtectWithPermission({
2323
+ permission,
2324
+ fallback,
2325
+ isLoaded,
2326
+ isSignedIn,
2327
+ children
2328
+ }) {
2329
+ const { allowed, isLoading } = usePermission(permission);
2330
+ if (!isLoaded || isLoading) {
2331
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "la-protect-loading", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "la-spinner" }) });
2332
+ }
2333
+ if (!isSignedIn || !allowed) {
2334
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children: fallback });
2335
+ }
2336
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children });
2337
+ }
2338
+ function resolveZanzibarSubject(explicit, user) {
2339
+ if (explicit) return explicit;
2340
+ const sub = user?.sub || user?.id;
2341
+ return sub ? `user:${sub}` : null;
2342
+ }
2343
+ function ProtectWithZanzibar({
2344
+ zanzibar,
2345
+ fallback,
2346
+ isLoaded,
2347
+ isSignedIn,
2348
+ user,
2349
+ children
2350
+ }) {
2351
+ if (!isLoaded) {
2352
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "la-protect-loading", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "la-spinner" }) });
2353
+ }
2354
+ const subject = isSignedIn ? resolveZanzibarSubject(zanzibar.subject, user) : null;
2355
+ if (!subject) {
2356
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children: fallback });
2357
+ }
2358
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2359
+ ZanzibarCheck,
2360
+ {
2361
+ object: zanzibar.object,
2362
+ relation: zanzibar.relation,
2363
+ subject,
2364
+ fallback,
2365
+ children
2366
+ }
2367
+ );
2368
+ }
2369
+ function ZanzibarCheck({
2370
+ object,
2371
+ relation,
2372
+ subject,
2373
+ fallback,
2374
+ children
2375
+ }) {
2376
+ const { allowed, isLoading } = useZanzibar({ object, relation, subject });
2377
+ if (isLoading) {
2378
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "la-protect-loading", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "la-spinner" }) });
2379
+ }
2380
+ return allowed ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children: fallback });
2381
+ }
2382
+ function ProtectWithAbac({
2383
+ abac,
2384
+ fallback,
2385
+ isLoaded,
2386
+ isSignedIn,
2387
+ children
2388
+ }) {
2389
+ const { allowed, isLoading } = useAbac({
2390
+ resourceType: abac.resourceType,
2391
+ action: abac.action,
2392
+ resourceId: abac.resourceId
2393
+ });
2394
+ if (!isLoaded || isLoading) {
2395
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "la-protect-loading", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "la-spinner" }) });
2396
+ }
2397
+ if (!isSignedIn || !allowed) {
2398
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children: fallback });
2399
+ }
2400
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children });
2401
+ }
2402
+
2403
+ // src/components/Control.tsx
2404
+ var import_react8 = require("react");
2405
+ var import_jsx_runtime9 = require("react/jsx-runtime");
2406
+ function SignedIn({ children }) {
2407
+ const { isLoaded, isSignedIn } = useLumoAuthContext();
2408
+ if (!isLoaded || !isSignedIn) return null;
2409
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_jsx_runtime9.Fragment, { children });
2410
+ }
2411
+ function SignedOut({ children }) {
2412
+ const { isLoaded, isSignedIn } = useLumoAuthContext();
2413
+ if (!isLoaded || isSignedIn) return null;
2414
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_jsx_runtime9.Fragment, { children });
2415
+ }
2416
+ function SignInButton({ children, signInUrl, className }) {
2417
+ const { signIn, authStrategy, config } = useLumoAuthContext();
2418
+ const handleClick = () => {
2419
+ if (authStrategy === "pkce") {
2420
+ signIn();
2421
+ } else if (signInUrl) {
2422
+ window.location.href = sanitizeRedirectUrl(signInUrl);
2423
+ } else {
2424
+ window.location.href = sanitizeRedirectUrl(config.afterSignInUrl || "/sign-in");
2425
+ }
2426
+ };
2427
+ if (children) {
2428
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { onClick: handleClick, role: "button", tabIndex: 0, onKeyDown: (e) => {
2429
+ if (e.key === "Enter" || e.key === " ") handleClick();
2430
+ }, children });
2431
+ }
2432
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("button", { type: "button", className, onClick: handleClick, children: "Sign in" });
2433
+ }
2434
+ function SignUpButton({ children, signUpUrl, className }) {
2435
+ const { config } = useLumoAuthContext();
2436
+ const handleClick = () => {
2437
+ const url = signUpUrl || config.afterSignUpUrl || "/sign-up";
2438
+ window.location.href = sanitizeRedirectUrl(url);
2439
+ };
2440
+ if (children) {
2441
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { onClick: handleClick, role: "button", tabIndex: 0, onKeyDown: (e) => {
2442
+ if (e.key === "Enter" || e.key === " ") handleClick();
2443
+ }, children });
2444
+ }
2445
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("button", { type: "button", className, onClick: handleClick, children: "Sign up" });
2446
+ }
2447
+ function SignOutButton({ children, afterSignOutUrl, className }) {
2448
+ const { signOut, config } = useLumoAuthContext();
2449
+ const handleClick = async () => {
2450
+ const redirectUrl = afterSignOutUrl || config.afterSignOutUrl || "/";
2451
+ await signOut({ afterSignOutUrl: sanitizeRedirectUrl(redirectUrl) });
2452
+ };
2453
+ if (children) {
2454
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { onClick: handleClick, role: "button", tabIndex: 0, onKeyDown: (e) => {
2455
+ if (e.key === "Enter" || e.key === " ") handleClick();
2456
+ }, children });
2457
+ }
2458
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("button", { type: "button", className, onClick: handleClick, children: "Sign out" });
2459
+ }
2460
+ function RedirectToSignIn({ signInUrl }) {
2461
+ const { signIn, authStrategy } = useLumoAuthContext();
2462
+ (0, import_react8.useEffect)(() => {
2463
+ if (authStrategy === "pkce") {
2464
+ signIn();
2465
+ } else if (signInUrl && typeof window !== "undefined") {
2466
+ window.location.href = sanitizeRedirectUrl(signInUrl);
2467
+ }
2468
+ }, [signIn, authStrategy, signInUrl]);
2469
+ return null;
2470
+ }
2471
+ // Annotate the CommonJS export names for ESM import in node:
2472
+ 0 && (module.exports = {
2473
+ AuthCallback,
2474
+ LumoAuth,
2475
+ LumoAuthProvider,
2476
+ Protect,
2477
+ RedirectToSignIn,
2478
+ SignIn,
2479
+ SignInButton,
2480
+ SignOutButton,
2481
+ SignUp,
2482
+ SignUpButton,
2483
+ SignedIn,
2484
+ SignedOut,
2485
+ UserAvatar,
2486
+ UserButton,
2487
+ UserProfile,
2488
+ useAbac,
2489
+ useAuth,
2490
+ useEmailFirst,
2491
+ useLumoAuth,
2492
+ useMagicLink,
2493
+ usePermission,
2494
+ useSession,
2495
+ useSignIn,
2496
+ useUser,
2497
+ useZanzibar
2498
+ });
2499
+ //# sourceMappingURL=index.js.map