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