dauth-context-react 5.0.0 → 6.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/README.md +101 -228
- package/dist/index.d.mts +22 -2
- package/dist/index.d.ts +22 -2
- package/dist/index.js +802 -96
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +807 -96
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -1
- package/src/DauthProfileModal.tsx +890 -0
- package/src/api/dauth.api.ts +6 -17
- package/src/api/interfaces/dauth.api.responses.ts +0 -7
- package/src/api/utils/config.ts +8 -5
- package/src/index.tsx +15 -26
- package/src/initialDauthState.ts +0 -1
- package/src/interfaces.ts +23 -6
- package/src/reducer/dauth.actions.ts +9 -61
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// src/index.tsx
|
|
2
2
|
import {
|
|
3
3
|
useReducer,
|
|
4
|
-
useMemo,
|
|
5
|
-
useEffect,
|
|
6
|
-
useCallback,
|
|
4
|
+
useMemo as useMemo2,
|
|
5
|
+
useEffect as useEffect2,
|
|
6
|
+
useCallback as useCallback2,
|
|
7
7
|
createContext,
|
|
8
8
|
useContext
|
|
9
9
|
} from "react";
|
|
@@ -21,8 +21,6 @@ var initialDauthState = {
|
|
|
21
21
|
logout: () => {
|
|
22
22
|
},
|
|
23
23
|
updateUser: () => Promise.resolve(false),
|
|
24
|
-
updateUserWithRedirect: () => {
|
|
25
|
-
},
|
|
26
24
|
deleteAccount: () => Promise.resolve(false)
|
|
27
25
|
};
|
|
28
26
|
var initialDauthState_default = initialDauthState;
|
|
@@ -72,7 +70,12 @@ function getCsrfToken() {
|
|
|
72
70
|
const match = document.cookie.match(
|
|
73
71
|
/(?:^|;\s*)(?:__Host-csrf|csrf-token)=([^;]*)/
|
|
74
72
|
);
|
|
75
|
-
|
|
73
|
+
if (!match?.[1]) return "";
|
|
74
|
+
try {
|
|
75
|
+
return decodeURIComponent(match[1]);
|
|
76
|
+
} catch {
|
|
77
|
+
return match[1];
|
|
78
|
+
}
|
|
76
79
|
}
|
|
77
80
|
async function exchangeCodeAPI(basePath, code) {
|
|
78
81
|
const response = await fetch(`${basePath}/exchange-code`, {
|
|
@@ -125,18 +128,6 @@ async function deleteAccountAPI(basePath) {
|
|
|
125
128
|
const data = await response.json();
|
|
126
129
|
return { response, data };
|
|
127
130
|
}
|
|
128
|
-
async function profileRedirectAPI(basePath) {
|
|
129
|
-
const response = await fetch(
|
|
130
|
-
`${basePath}/profile-redirect`,
|
|
131
|
-
{
|
|
132
|
-
method: "GET",
|
|
133
|
-
headers: { "X-CSRF-Token": getCsrfToken() },
|
|
134
|
-
credentials: "include"
|
|
135
|
-
}
|
|
136
|
-
);
|
|
137
|
-
const data = await response.json();
|
|
138
|
-
return { response, data };
|
|
139
|
-
}
|
|
140
131
|
|
|
141
132
|
// src/reducer/dauth.actions.ts
|
|
142
133
|
async function exchangeCodeAction(ctx, code) {
|
|
@@ -146,11 +137,7 @@ async function exchangeCodeAction(ctx, code) {
|
|
|
146
137
|
payload: { isLoading: true }
|
|
147
138
|
});
|
|
148
139
|
try {
|
|
149
|
-
window.history.replaceState(
|
|
150
|
-
{},
|
|
151
|
-
document.title,
|
|
152
|
-
window.location.pathname
|
|
153
|
-
);
|
|
140
|
+
window.history.replaceState({}, document.title, window.location.pathname);
|
|
154
141
|
const result = await exchangeCodeAPI(authProxyPath, code);
|
|
155
142
|
if (result.response.status === 200) {
|
|
156
143
|
dispatch({
|
|
@@ -165,9 +152,7 @@ async function exchangeCodeAction(ctx, code) {
|
|
|
165
152
|
}
|
|
166
153
|
resetUser(dispatch);
|
|
167
154
|
} catch (error) {
|
|
168
|
-
onError(
|
|
169
|
-
error instanceof Error ? error : new Error(String(error))
|
|
170
|
-
);
|
|
155
|
+
onError(error instanceof Error ? error : new Error(String(error)));
|
|
171
156
|
resetUser(dispatch);
|
|
172
157
|
} finally {
|
|
173
158
|
dispatch({
|
|
@@ -197,9 +182,7 @@ async function autoLoginAction(ctx) {
|
|
|
197
182
|
}
|
|
198
183
|
resetUser(dispatch);
|
|
199
184
|
} catch (error) {
|
|
200
|
-
onError(
|
|
201
|
-
error instanceof Error ? error : new Error(String(error))
|
|
202
|
-
);
|
|
185
|
+
onError(error instanceof Error ? error : new Error(String(error)));
|
|
203
186
|
resetUser(dispatch);
|
|
204
187
|
} finally {
|
|
205
188
|
dispatch({
|
|
@@ -236,10 +219,7 @@ async function logoutAction(ctx) {
|
|
|
236
219
|
async function updateUserAction(ctx, user) {
|
|
237
220
|
const { dispatch, authProxyPath, onError } = ctx;
|
|
238
221
|
if (user.language) {
|
|
239
|
-
window.document.documentElement.setAttribute(
|
|
240
|
-
"lang",
|
|
241
|
-
user.language
|
|
242
|
-
);
|
|
222
|
+
window.document.documentElement.setAttribute("lang", user.language);
|
|
243
223
|
}
|
|
244
224
|
try {
|
|
245
225
|
const result = await updateUserAPI(authProxyPath, user);
|
|
@@ -250,34 +230,13 @@ async function updateUserAction(ctx, user) {
|
|
|
250
230
|
});
|
|
251
231
|
return true;
|
|
252
232
|
}
|
|
253
|
-
onError(
|
|
254
|
-
new Error("Update user error: " + result.data.message)
|
|
255
|
-
);
|
|
233
|
+
onError(new Error("Update user error: " + result.data.message));
|
|
256
234
|
return false;
|
|
257
235
|
} catch (error) {
|
|
258
|
-
onError(
|
|
259
|
-
error instanceof Error ? error : new Error("Update user error")
|
|
260
|
-
);
|
|
236
|
+
onError(error instanceof Error ? error : new Error("Update user error"));
|
|
261
237
|
return false;
|
|
262
238
|
}
|
|
263
239
|
}
|
|
264
|
-
async function updateUserWithRedirectAction(ctx) {
|
|
265
|
-
const { authProxyPath, onError } = ctx;
|
|
266
|
-
try {
|
|
267
|
-
const result = await profileRedirectAPI(authProxyPath);
|
|
268
|
-
if (result.response.status === 200 && result.data.redirectUrl) {
|
|
269
|
-
window.location.replace(result.data.redirectUrl);
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
onError(
|
|
273
|
-
new Error("Could not generate profile redirect")
|
|
274
|
-
);
|
|
275
|
-
} catch (error) {
|
|
276
|
-
onError(
|
|
277
|
-
error instanceof Error ? error : new Error("Profile redirect error")
|
|
278
|
-
);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
240
|
async function deleteAccountAction(ctx) {
|
|
282
241
|
const { dispatch, authProxyPath, onError } = ctx;
|
|
283
242
|
try {
|
|
@@ -288,9 +247,7 @@ async function deleteAccountAction(ctx) {
|
|
|
288
247
|
}
|
|
289
248
|
return false;
|
|
290
249
|
} catch (error) {
|
|
291
|
-
onError(
|
|
292
|
-
error instanceof Error ? error : new Error("Delete account error")
|
|
293
|
-
);
|
|
250
|
+
onError(error instanceof Error ? error : new Error("Delete account error"));
|
|
294
251
|
return false;
|
|
295
252
|
}
|
|
296
253
|
}
|
|
@@ -314,12 +271,12 @@ function setDauthUrl(url) {
|
|
|
314
271
|
function checkIsLocalhost() {
|
|
315
272
|
if (typeof window === "undefined") return false;
|
|
316
273
|
const hostname = window.location.hostname;
|
|
317
|
-
return
|
|
318
|
-
hostname
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
274
|
+
return hostname === "localhost" || hostname === "[::1]" || /^127(?:\.(?:25[0-5]|2[0-4]\d|[01]?\d\d?)){3}$/.test(
|
|
275
|
+
hostname
|
|
276
|
+
) || /^192\.168(?:\.(?:25[0-5]|2[0-4]\d|[01]?\d\d?)){2}$/.test(
|
|
277
|
+
hostname
|
|
278
|
+
) || /^10(?:\.(?:25[0-5]|2[0-4]\d|[01]?\d\d?)){3}$/.test(
|
|
279
|
+
hostname
|
|
323
280
|
);
|
|
324
281
|
}
|
|
325
282
|
function getClientBasePath() {
|
|
@@ -339,8 +296,779 @@ var routes = {
|
|
|
339
296
|
signin: "signin"
|
|
340
297
|
};
|
|
341
298
|
|
|
299
|
+
// src/DauthProfileModal.tsx
|
|
300
|
+
import {
|
|
301
|
+
useCallback,
|
|
302
|
+
useEffect,
|
|
303
|
+
useMemo,
|
|
304
|
+
useRef,
|
|
305
|
+
useState
|
|
306
|
+
} from "react";
|
|
307
|
+
import { createPortal } from "react-dom";
|
|
308
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
309
|
+
var TRANSITION_MS = 200;
|
|
310
|
+
var MOBILE_TRANSITION_MS = 300;
|
|
311
|
+
var SUCCESS_TIMEOUT_MS = 4e3;
|
|
312
|
+
var CONFIRM_WORD = "DELETE";
|
|
313
|
+
function IconClose() {
|
|
314
|
+
return /* @__PURE__ */ jsxs(
|
|
315
|
+
"svg",
|
|
316
|
+
{
|
|
317
|
+
width: "20",
|
|
318
|
+
height: "20",
|
|
319
|
+
viewBox: "0 0 24 24",
|
|
320
|
+
fill: "none",
|
|
321
|
+
stroke: "currentColor",
|
|
322
|
+
strokeWidth: "2",
|
|
323
|
+
strokeLinecap: "round",
|
|
324
|
+
strokeLinejoin: "round",
|
|
325
|
+
children: [
|
|
326
|
+
/* @__PURE__ */ jsx("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
|
|
327
|
+
/* @__PURE__ */ jsx("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
|
|
328
|
+
]
|
|
329
|
+
}
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
function IconBack() {
|
|
333
|
+
return /* @__PURE__ */ jsxs(
|
|
334
|
+
"svg",
|
|
335
|
+
{
|
|
336
|
+
width: "20",
|
|
337
|
+
height: "20",
|
|
338
|
+
viewBox: "0 0 24 24",
|
|
339
|
+
fill: "none",
|
|
340
|
+
stroke: "currentColor",
|
|
341
|
+
strokeWidth: "2",
|
|
342
|
+
strokeLinecap: "round",
|
|
343
|
+
strokeLinejoin: "round",
|
|
344
|
+
children: [
|
|
345
|
+
/* @__PURE__ */ jsx("line", { x1: "19", y1: "12", x2: "5", y2: "12" }),
|
|
346
|
+
/* @__PURE__ */ jsx("polyline", { points: "12 19 5 12 12 5" })
|
|
347
|
+
]
|
|
348
|
+
}
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
function Spinner() {
|
|
352
|
+
return /* @__PURE__ */ jsx("span", { style: spinnerStyle, "aria-hidden": "true" });
|
|
353
|
+
}
|
|
354
|
+
function useMediaQuery(query) {
|
|
355
|
+
const [matches, setMatches] = useState(
|
|
356
|
+
() => typeof window !== "undefined" && window.matchMedia(query).matches
|
|
357
|
+
);
|
|
358
|
+
useEffect(() => {
|
|
359
|
+
const mq = window.matchMedia(query);
|
|
360
|
+
const handler = (e) => setMatches(e.matches);
|
|
361
|
+
mq.addEventListener("change", handler);
|
|
362
|
+
return () => mq.removeEventListener("change", handler);
|
|
363
|
+
}, [query]);
|
|
364
|
+
return matches;
|
|
365
|
+
}
|
|
366
|
+
function useModalAnimation(open) {
|
|
367
|
+
const [phase, setPhase] = useState("exited");
|
|
368
|
+
useEffect(() => {
|
|
369
|
+
if (open) {
|
|
370
|
+
setPhase("entering");
|
|
371
|
+
const raf = requestAnimationFrame(() => {
|
|
372
|
+
requestAnimationFrame(() => setPhase("entered"));
|
|
373
|
+
});
|
|
374
|
+
return () => cancelAnimationFrame(raf);
|
|
375
|
+
}
|
|
376
|
+
if (phase === "entered" || phase === "entering") {
|
|
377
|
+
setPhase("exiting");
|
|
378
|
+
const timer = setTimeout(() => setPhase("exited"), MOBILE_TRANSITION_MS);
|
|
379
|
+
return () => clearTimeout(timer);
|
|
380
|
+
}
|
|
381
|
+
return void 0;
|
|
382
|
+
}, [open]);
|
|
383
|
+
return phase;
|
|
384
|
+
}
|
|
385
|
+
function useFocusTrap(containerRef, active, onEscape) {
|
|
386
|
+
const previousFocus = useRef(null);
|
|
387
|
+
useEffect(() => {
|
|
388
|
+
if (!active) return;
|
|
389
|
+
previousFocus.current = document.activeElement;
|
|
390
|
+
const container = containerRef.current;
|
|
391
|
+
if (!container) return;
|
|
392
|
+
const focusFirst = () => {
|
|
393
|
+
const firstInput = container.querySelector(
|
|
394
|
+
"input:not([disabled])"
|
|
395
|
+
);
|
|
396
|
+
(firstInput ?? container).focus();
|
|
397
|
+
};
|
|
398
|
+
const raf = requestAnimationFrame(focusFirst);
|
|
399
|
+
const handleKeyDown = (e) => {
|
|
400
|
+
if (e.key === "Escape") {
|
|
401
|
+
e.preventDefault();
|
|
402
|
+
onEscape();
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
if (e.key !== "Tab") return;
|
|
406
|
+
const focusable = container.querySelectorAll(
|
|
407
|
+
'button:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex="-1"])'
|
|
408
|
+
);
|
|
409
|
+
if (focusable.length === 0) return;
|
|
410
|
+
const first = focusable[0];
|
|
411
|
+
const last = focusable[focusable.length - 1];
|
|
412
|
+
if (e.shiftKey && document.activeElement === first) {
|
|
413
|
+
e.preventDefault();
|
|
414
|
+
last.focus();
|
|
415
|
+
} else if (!e.shiftKey && document.activeElement === last) {
|
|
416
|
+
e.preventDefault();
|
|
417
|
+
first.focus();
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
421
|
+
return () => {
|
|
422
|
+
cancelAnimationFrame(raf);
|
|
423
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
424
|
+
if (previousFocus.current instanceof HTMLElement) {
|
|
425
|
+
previousFocus.current.focus();
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
}, [active, containerRef, onEscape]);
|
|
429
|
+
}
|
|
430
|
+
function useScrollLock(active) {
|
|
431
|
+
useEffect(() => {
|
|
432
|
+
if (!active) return;
|
|
433
|
+
const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
|
|
434
|
+
const prevOverflow = document.body.style.overflow;
|
|
435
|
+
const prevPaddingRight = document.body.style.paddingRight;
|
|
436
|
+
document.body.style.overflow = "hidden";
|
|
437
|
+
if (scrollbarWidth > 0) {
|
|
438
|
+
document.body.style.paddingRight = `${scrollbarWidth}px`;
|
|
439
|
+
}
|
|
440
|
+
return () => {
|
|
441
|
+
document.body.style.overflow = prevOverflow;
|
|
442
|
+
document.body.style.paddingRight = prevPaddingRight;
|
|
443
|
+
};
|
|
444
|
+
}, [active]);
|
|
445
|
+
}
|
|
446
|
+
function DauthProfileModal({ open, onClose }) {
|
|
447
|
+
const { user, domain, updateUser, deleteAccount } = useDauth();
|
|
448
|
+
const isDesktop = useMediaQuery("(min-width: 641px)");
|
|
449
|
+
const phase = useModalAnimation(open);
|
|
450
|
+
const modalRef = useRef(null);
|
|
451
|
+
const [name, setName] = useState("");
|
|
452
|
+
const [lastname, setLastname] = useState("");
|
|
453
|
+
const [nickname, setNickname] = useState("");
|
|
454
|
+
const [country, setCountry] = useState("");
|
|
455
|
+
const [populated, setPopulated] = useState(false);
|
|
456
|
+
const [saving, setSaving] = useState(false);
|
|
457
|
+
const [status, setStatus] = useState(null);
|
|
458
|
+
const [showDelete, setShowDelete] = useState(false);
|
|
459
|
+
const [deleteText, setDeleteText] = useState("");
|
|
460
|
+
const [deleting, setDeleting] = useState(false);
|
|
461
|
+
useEffect(() => {
|
|
462
|
+
if (open && user?._id && !populated) {
|
|
463
|
+
setName(user.name || "");
|
|
464
|
+
setLastname(user.lastname || "");
|
|
465
|
+
setNickname(user.nickname || "");
|
|
466
|
+
setCountry(user.country || "");
|
|
467
|
+
setPopulated(true);
|
|
468
|
+
}
|
|
469
|
+
if (!open) {
|
|
470
|
+
setPopulated(false);
|
|
471
|
+
setStatus(null);
|
|
472
|
+
setShowDelete(false);
|
|
473
|
+
setDeleteText("");
|
|
474
|
+
}
|
|
475
|
+
}, [open, user, populated]);
|
|
476
|
+
useEffect(() => {
|
|
477
|
+
if (status?.type !== "success") return;
|
|
478
|
+
const timer = setTimeout(() => setStatus(null), SUCCESS_TIMEOUT_MS);
|
|
479
|
+
return () => clearTimeout(timer);
|
|
480
|
+
}, [status]);
|
|
481
|
+
useFocusTrap(modalRef, phase === "entered", onClose);
|
|
482
|
+
useScrollLock(phase !== "exited");
|
|
483
|
+
const hasField = useCallback(
|
|
484
|
+
(field) => domain.formFields?.some((f) => f.field === field) ?? false,
|
|
485
|
+
[domain.formFields]
|
|
486
|
+
);
|
|
487
|
+
const isRequired = useCallback(
|
|
488
|
+
(field) => domain.formFields?.find((f) => f.field === field)?.required ?? false,
|
|
489
|
+
[domain.formFields]
|
|
490
|
+
);
|
|
491
|
+
const hasChanges = useMemo(() => {
|
|
492
|
+
if (!user?._id) return false;
|
|
493
|
+
return name !== (user.name || "") || lastname !== (user.lastname || "") || nickname !== (user.nickname || "") || country !== (user.country || "");
|
|
494
|
+
}, [name, lastname, nickname, country, user]);
|
|
495
|
+
const canSave = name.trim().length > 0 && hasChanges && !saving;
|
|
496
|
+
const handleSave = useCallback(async () => {
|
|
497
|
+
setSaving(true);
|
|
498
|
+
setStatus(null);
|
|
499
|
+
const fields = { name };
|
|
500
|
+
if (hasField("lastname")) fields.lastname = lastname;
|
|
501
|
+
if (hasField("nickname")) fields.nickname = nickname;
|
|
502
|
+
if (hasField("country")) fields.country = country;
|
|
503
|
+
const ok = await updateUser(fields);
|
|
504
|
+
setSaving(false);
|
|
505
|
+
if (ok) {
|
|
506
|
+
setStatus({
|
|
507
|
+
type: "success",
|
|
508
|
+
message: "Profile updated successfully"
|
|
509
|
+
});
|
|
510
|
+
} else {
|
|
511
|
+
setStatus({
|
|
512
|
+
type: "error",
|
|
513
|
+
message: "Something went wrong. Please try again."
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
}, [name, lastname, nickname, country, hasField, updateUser]);
|
|
517
|
+
const handleDelete = useCallback(async () => {
|
|
518
|
+
setDeleting(true);
|
|
519
|
+
const ok = await deleteAccount();
|
|
520
|
+
setDeleting(false);
|
|
521
|
+
if (ok) {
|
|
522
|
+
onClose();
|
|
523
|
+
} else {
|
|
524
|
+
setStatus({
|
|
525
|
+
type: "error",
|
|
526
|
+
message: "Could not delete account. Please try again."
|
|
527
|
+
});
|
|
528
|
+
setShowDelete(false);
|
|
529
|
+
setDeleteText("");
|
|
530
|
+
}
|
|
531
|
+
}, [deleteAccount, onClose]);
|
|
532
|
+
const themeVars = useMemo(() => {
|
|
533
|
+
const t = domain.modalTheme;
|
|
534
|
+
if (!t) return {};
|
|
535
|
+
const vars = {};
|
|
536
|
+
if (t.accent) vars["--dauth-accent"] = t.accent;
|
|
537
|
+
if (t.accentHover) vars["--dauth-accent-hover"] = t.accentHover;
|
|
538
|
+
if (t.surface) vars["--dauth-surface"] = t.surface;
|
|
539
|
+
if (t.surfaceHover) vars["--dauth-surface-hover"] = t.surfaceHover;
|
|
540
|
+
if (t.textPrimary) vars["--dauth-text-primary"] = t.textPrimary;
|
|
541
|
+
if (t.textSecondary) vars["--dauth-text-secondary"] = t.textSecondary;
|
|
542
|
+
if (t.border) vars["--dauth-border"] = t.border;
|
|
543
|
+
return vars;
|
|
544
|
+
}, [domain.modalTheme]);
|
|
545
|
+
if (phase === "exited") return null;
|
|
546
|
+
const dur = isDesktop ? TRANSITION_MS : MOBILE_TRANSITION_MS;
|
|
547
|
+
const easing = "cubic-bezier(0.16, 1, 0.3, 1)";
|
|
548
|
+
const backdrop = {
|
|
549
|
+
position: "fixed",
|
|
550
|
+
inset: 0,
|
|
551
|
+
zIndex: 2147483647,
|
|
552
|
+
backgroundColor: "var(--dauth-backdrop, rgba(0, 0, 0, 0.6))",
|
|
553
|
+
backdropFilter: "blur(4px)",
|
|
554
|
+
WebkitBackdropFilter: "blur(4px)",
|
|
555
|
+
display: "flex",
|
|
556
|
+
alignItems: "center",
|
|
557
|
+
justifyContent: "center",
|
|
558
|
+
opacity: phase === "entered" ? 1 : 0,
|
|
559
|
+
transition: `opacity ${dur}ms ease-out`
|
|
560
|
+
};
|
|
561
|
+
const modalDesktop = {
|
|
562
|
+
position: "relative",
|
|
563
|
+
width: "100%",
|
|
564
|
+
maxWidth: 480,
|
|
565
|
+
maxHeight: "90vh",
|
|
566
|
+
margin: 16,
|
|
567
|
+
backgroundColor: "var(--dauth-surface, #1a1a2e)",
|
|
568
|
+
borderRadius: "var(--dauth-radius, 12px)",
|
|
569
|
+
boxShadow: "var(--dauth-shadow, 0 25px 50px -12px rgba(0, 0, 0, 0.5))",
|
|
570
|
+
border: "1px solid var(--dauth-border, rgba(255, 255, 255, 0.08))",
|
|
571
|
+
display: "flex",
|
|
572
|
+
flexDirection: "column",
|
|
573
|
+
overflow: "hidden",
|
|
574
|
+
fontFamily: "var(--dauth-font-family, system-ui, -apple-system, sans-serif)",
|
|
575
|
+
color: "var(--dauth-text-primary, #e4e4e7)",
|
|
576
|
+
opacity: phase === "entered" ? 1 : 0,
|
|
577
|
+
transform: phase === "entered" ? "translateY(0)" : "translateY(16px)",
|
|
578
|
+
transition: `opacity ${dur}ms ${easing}, transform ${dur}ms ${easing}`
|
|
579
|
+
};
|
|
580
|
+
const modalMobile = {
|
|
581
|
+
position: "fixed",
|
|
582
|
+
inset: 0,
|
|
583
|
+
backgroundColor: "var(--dauth-surface, #1a1a2e)",
|
|
584
|
+
display: "flex",
|
|
585
|
+
flexDirection: "column",
|
|
586
|
+
fontFamily: "var(--dauth-font-family, system-ui, -apple-system, sans-serif)",
|
|
587
|
+
color: "var(--dauth-text-primary, #e4e4e7)",
|
|
588
|
+
transform: phase === "entered" ? "translateY(0)" : "translateY(100%)",
|
|
589
|
+
transition: `transform ${dur}ms ${easing}`
|
|
590
|
+
};
|
|
591
|
+
const avatarInitial = (user.name || user.email || "?").charAt(0).toUpperCase();
|
|
592
|
+
return createPortal(
|
|
593
|
+
/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
594
|
+
/* @__PURE__ */ jsx(
|
|
595
|
+
"style",
|
|
596
|
+
{
|
|
597
|
+
dangerouslySetInnerHTML: {
|
|
598
|
+
__html: "@keyframes dauth-spin{to{transform:rotate(360deg)}}"
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
),
|
|
602
|
+
/* @__PURE__ */ jsx(
|
|
603
|
+
"div",
|
|
604
|
+
{
|
|
605
|
+
style: { ...backdrop, ...themeVars },
|
|
606
|
+
onClick: isDesktop ? onClose : void 0,
|
|
607
|
+
"data-testid": "dauth-profile-backdrop",
|
|
608
|
+
children: /* @__PURE__ */ jsxs(
|
|
609
|
+
"div",
|
|
610
|
+
{
|
|
611
|
+
ref: modalRef,
|
|
612
|
+
role: "dialog",
|
|
613
|
+
"aria-modal": "true",
|
|
614
|
+
"aria-labelledby": "dauth-profile-title",
|
|
615
|
+
style: isDesktop ? modalDesktop : modalMobile,
|
|
616
|
+
onClick: (e) => e.stopPropagation(),
|
|
617
|
+
tabIndex: -1,
|
|
618
|
+
children: [
|
|
619
|
+
/* @__PURE__ */ jsxs("div", { style: headerStyle(isDesktop), children: [
|
|
620
|
+
/* @__PURE__ */ jsx(
|
|
621
|
+
"button",
|
|
622
|
+
{
|
|
623
|
+
type: "button",
|
|
624
|
+
onClick: onClose,
|
|
625
|
+
style: closeBtn,
|
|
626
|
+
"aria-label": "Close",
|
|
627
|
+
onMouseEnter: (e) => e.currentTarget.style.backgroundColor = "var(--dauth-surface-hover, #232340)",
|
|
628
|
+
onMouseLeave: (e) => e.currentTarget.style.backgroundColor = "transparent",
|
|
629
|
+
children: isDesktop ? /* @__PURE__ */ jsx(IconClose, {}) : /* @__PURE__ */ jsx(IconBack, {})
|
|
630
|
+
}
|
|
631
|
+
),
|
|
632
|
+
/* @__PURE__ */ jsx("h2", { id: "dauth-profile-title", style: titleStyle, children: "Your Profile" }),
|
|
633
|
+
/* @__PURE__ */ jsx("div", { style: { width: 36 } })
|
|
634
|
+
] }),
|
|
635
|
+
/* @__PURE__ */ jsxs("div", { style: bodyStyle, children: [
|
|
636
|
+
/* @__PURE__ */ jsxs("div", { style: avatarSection, children: [
|
|
637
|
+
/* @__PURE__ */ jsx("div", { style: avatarCircle, children: user.avatar?.url ? /* @__PURE__ */ jsx(
|
|
638
|
+
"img",
|
|
639
|
+
{
|
|
640
|
+
src: user.avatar.url,
|
|
641
|
+
alt: "",
|
|
642
|
+
style: {
|
|
643
|
+
width: "100%",
|
|
644
|
+
height: "100%",
|
|
645
|
+
objectFit: "cover"
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
) : avatarInitial }),
|
|
649
|
+
/* @__PURE__ */ jsx("div", { style: emailText, children: user.email })
|
|
650
|
+
] }),
|
|
651
|
+
status && /* @__PURE__ */ jsx(
|
|
652
|
+
"div",
|
|
653
|
+
{
|
|
654
|
+
role: "status",
|
|
655
|
+
"aria-live": "polite",
|
|
656
|
+
style: statusMsg(status.type),
|
|
657
|
+
children: status.message
|
|
658
|
+
}
|
|
659
|
+
),
|
|
660
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
661
|
+
/* @__PURE__ */ jsxs("div", { style: fieldGroup, children: [
|
|
662
|
+
/* @__PURE__ */ jsx("label", { htmlFor: "dauth-name", style: label, children: "Name *" }),
|
|
663
|
+
/* @__PURE__ */ jsx(
|
|
664
|
+
"input",
|
|
665
|
+
{
|
|
666
|
+
id: "dauth-name",
|
|
667
|
+
type: "text",
|
|
668
|
+
value: name,
|
|
669
|
+
onChange: (e) => setName(e.target.value),
|
|
670
|
+
placeholder: "Your name",
|
|
671
|
+
disabled: saving,
|
|
672
|
+
style: input,
|
|
673
|
+
onFocus: inputFocusHandler,
|
|
674
|
+
onBlur: inputBlurHandler
|
|
675
|
+
}
|
|
676
|
+
)
|
|
677
|
+
] }),
|
|
678
|
+
hasField("lastname") && /* @__PURE__ */ jsxs("div", { style: fieldGroup, children: [
|
|
679
|
+
/* @__PURE__ */ jsxs("label", { htmlFor: "dauth-lastname", style: label, children: [
|
|
680
|
+
"Last name",
|
|
681
|
+
isRequired("lastname") ? " *" : ""
|
|
682
|
+
] }),
|
|
683
|
+
/* @__PURE__ */ jsx(
|
|
684
|
+
"input",
|
|
685
|
+
{
|
|
686
|
+
id: "dauth-lastname",
|
|
687
|
+
type: "text",
|
|
688
|
+
value: lastname,
|
|
689
|
+
onChange: (e) => setLastname(e.target.value),
|
|
690
|
+
placeholder: "Your last name",
|
|
691
|
+
disabled: saving,
|
|
692
|
+
style: input,
|
|
693
|
+
onFocus: inputFocusHandler,
|
|
694
|
+
onBlur: inputBlurHandler
|
|
695
|
+
}
|
|
696
|
+
)
|
|
697
|
+
] }),
|
|
698
|
+
hasField("nickname") && /* @__PURE__ */ jsxs("div", { style: fieldGroup, children: [
|
|
699
|
+
/* @__PURE__ */ jsxs("label", { htmlFor: "dauth-nickname", style: label, children: [
|
|
700
|
+
"Nickname",
|
|
701
|
+
isRequired("nickname") ? " *" : ""
|
|
702
|
+
] }),
|
|
703
|
+
/* @__PURE__ */ jsx(
|
|
704
|
+
"input",
|
|
705
|
+
{
|
|
706
|
+
id: "dauth-nickname",
|
|
707
|
+
type: "text",
|
|
708
|
+
value: nickname,
|
|
709
|
+
onChange: (e) => setNickname(e.target.value),
|
|
710
|
+
placeholder: "Choose a nickname",
|
|
711
|
+
disabled: saving,
|
|
712
|
+
style: input,
|
|
713
|
+
onFocus: inputFocusHandler,
|
|
714
|
+
onBlur: inputBlurHandler
|
|
715
|
+
}
|
|
716
|
+
)
|
|
717
|
+
] }),
|
|
718
|
+
hasField("country") && /* @__PURE__ */ jsxs("div", { style: fieldGroup, children: [
|
|
719
|
+
/* @__PURE__ */ jsxs("label", { htmlFor: "dauth-country", style: label, children: [
|
|
720
|
+
"Country",
|
|
721
|
+
isRequired("country") ? " *" : ""
|
|
722
|
+
] }),
|
|
723
|
+
/* @__PURE__ */ jsx(
|
|
724
|
+
"input",
|
|
725
|
+
{
|
|
726
|
+
id: "dauth-country",
|
|
727
|
+
type: "text",
|
|
728
|
+
value: country,
|
|
729
|
+
onChange: (e) => setCountry(e.target.value),
|
|
730
|
+
placeholder: "Your country",
|
|
731
|
+
disabled: saving,
|
|
732
|
+
style: input,
|
|
733
|
+
onFocus: inputFocusHandler,
|
|
734
|
+
onBlur: inputBlurHandler
|
|
735
|
+
}
|
|
736
|
+
)
|
|
737
|
+
] })
|
|
738
|
+
] }),
|
|
739
|
+
/* @__PURE__ */ jsx("hr", { style: separator }),
|
|
740
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
741
|
+
/* @__PURE__ */ jsx("div", { style: dangerTitle, children: "Delete account" }),
|
|
742
|
+
/* @__PURE__ */ jsx("div", { style: dangerDesc, children: "Permanently delete your account and all associated data." }),
|
|
743
|
+
!showDelete ? /* @__PURE__ */ jsx(
|
|
744
|
+
"button",
|
|
745
|
+
{
|
|
746
|
+
type: "button",
|
|
747
|
+
style: deleteBtn,
|
|
748
|
+
onClick: () => setShowDelete(true),
|
|
749
|
+
onMouseEnter: (e) => e.currentTarget.style.backgroundColor = "rgba(239, 68, 68, 0.2)",
|
|
750
|
+
onMouseLeave: (e) => e.currentTarget.style.backgroundColor = "var(--dauth-error-bg, rgba(239, 68, 68, 0.1))",
|
|
751
|
+
children: "Delete account"
|
|
752
|
+
}
|
|
753
|
+
) : /* @__PURE__ */ jsxs("div", { style: deletePanel, children: [
|
|
754
|
+
/* @__PURE__ */ jsxs("div", { style: deletePanelText, children: [
|
|
755
|
+
"This action is permanent and cannot be undone. Type",
|
|
756
|
+
" ",
|
|
757
|
+
/* @__PURE__ */ jsx("strong", { children: CONFIRM_WORD }),
|
|
758
|
+
" to confirm."
|
|
759
|
+
] }),
|
|
760
|
+
/* @__PURE__ */ jsx(
|
|
761
|
+
"input",
|
|
762
|
+
{
|
|
763
|
+
type: "text",
|
|
764
|
+
value: deleteText,
|
|
765
|
+
onChange: (e) => setDeleteText(e.target.value),
|
|
766
|
+
placeholder: `Type ${CONFIRM_WORD}`,
|
|
767
|
+
style: input,
|
|
768
|
+
onFocus: inputFocusHandler,
|
|
769
|
+
onBlur: inputBlurHandler,
|
|
770
|
+
disabled: deleting
|
|
771
|
+
}
|
|
772
|
+
),
|
|
773
|
+
/* @__PURE__ */ jsxs(
|
|
774
|
+
"div",
|
|
775
|
+
{
|
|
776
|
+
style: {
|
|
777
|
+
display: "flex",
|
|
778
|
+
gap: 8,
|
|
779
|
+
marginTop: 12
|
|
780
|
+
},
|
|
781
|
+
children: [
|
|
782
|
+
/* @__PURE__ */ jsx(
|
|
783
|
+
"button",
|
|
784
|
+
{
|
|
785
|
+
type: "button",
|
|
786
|
+
style: cancelBtn,
|
|
787
|
+
onClick: () => {
|
|
788
|
+
setShowDelete(false);
|
|
789
|
+
setDeleteText("");
|
|
790
|
+
},
|
|
791
|
+
onMouseEnter: (e) => e.currentTarget.style.backgroundColor = "var(--dauth-surface-hover, #232340)",
|
|
792
|
+
onMouseLeave: (e) => e.currentTarget.style.backgroundColor = "transparent",
|
|
793
|
+
children: "Cancel"
|
|
794
|
+
}
|
|
795
|
+
),
|
|
796
|
+
/* @__PURE__ */ jsxs(
|
|
797
|
+
"button",
|
|
798
|
+
{
|
|
799
|
+
type: "button",
|
|
800
|
+
style: {
|
|
801
|
+
...deleteConfirmBtn,
|
|
802
|
+
opacity: deleteText !== CONFIRM_WORD || deleting ? 0.5 : 1,
|
|
803
|
+
cursor: deleteText !== CONFIRM_WORD || deleting ? "not-allowed" : "pointer"
|
|
804
|
+
},
|
|
805
|
+
disabled: deleteText !== CONFIRM_WORD || deleting,
|
|
806
|
+
onClick: handleDelete,
|
|
807
|
+
children: [
|
|
808
|
+
deleting && /* @__PURE__ */ jsx(Spinner, {}),
|
|
809
|
+
"Delete my account"
|
|
810
|
+
]
|
|
811
|
+
}
|
|
812
|
+
)
|
|
813
|
+
]
|
|
814
|
+
}
|
|
815
|
+
)
|
|
816
|
+
] })
|
|
817
|
+
] })
|
|
818
|
+
] }),
|
|
819
|
+
/* @__PURE__ */ jsx("div", { style: footerStyle(isDesktop), children: /* @__PURE__ */ jsxs(
|
|
820
|
+
"button",
|
|
821
|
+
{
|
|
822
|
+
type: "button",
|
|
823
|
+
style: {
|
|
824
|
+
...saveBtn,
|
|
825
|
+
opacity: canSave ? 1 : 0.5,
|
|
826
|
+
cursor: canSave ? "pointer" : "not-allowed"
|
|
827
|
+
},
|
|
828
|
+
disabled: !canSave,
|
|
829
|
+
onClick: handleSave,
|
|
830
|
+
"aria-busy": saving,
|
|
831
|
+
onMouseEnter: (e) => {
|
|
832
|
+
if (canSave)
|
|
833
|
+
e.currentTarget.style.backgroundColor = "var(--dauth-accent-hover, #818cf8)";
|
|
834
|
+
},
|
|
835
|
+
onMouseLeave: (e) => {
|
|
836
|
+
e.currentTarget.style.backgroundColor = "var(--dauth-accent, #6366f1)";
|
|
837
|
+
},
|
|
838
|
+
children: [
|
|
839
|
+
saving && /* @__PURE__ */ jsx(Spinner, {}),
|
|
840
|
+
saving ? "Saving..." : "Save changes"
|
|
841
|
+
]
|
|
842
|
+
}
|
|
843
|
+
) })
|
|
844
|
+
]
|
|
845
|
+
}
|
|
846
|
+
)
|
|
847
|
+
}
|
|
848
|
+
)
|
|
849
|
+
] }),
|
|
850
|
+
document.body
|
|
851
|
+
);
|
|
852
|
+
}
|
|
853
|
+
var headerStyle = (isDesktop) => ({
|
|
854
|
+
display: "flex",
|
|
855
|
+
alignItems: "center",
|
|
856
|
+
justifyContent: "space-between",
|
|
857
|
+
padding: "16px 24px",
|
|
858
|
+
borderBottom: "1px solid var(--dauth-border, rgba(255, 255, 255, 0.08))",
|
|
859
|
+
flexShrink: 0,
|
|
860
|
+
...!isDesktop ? {
|
|
861
|
+
position: "sticky",
|
|
862
|
+
top: 0,
|
|
863
|
+
zIndex: 1,
|
|
864
|
+
backgroundColor: "var(--dauth-surface, #1a1a2e)"
|
|
865
|
+
} : {}
|
|
866
|
+
});
|
|
867
|
+
var titleStyle = {
|
|
868
|
+
fontSize: "var(--dauth-font-size-lg, 1.25rem)",
|
|
869
|
+
fontWeight: 600,
|
|
870
|
+
margin: 0,
|
|
871
|
+
lineHeight: 1.4,
|
|
872
|
+
textAlign: "center",
|
|
873
|
+
flex: 1
|
|
874
|
+
};
|
|
875
|
+
var closeBtn = {
|
|
876
|
+
display: "flex",
|
|
877
|
+
alignItems: "center",
|
|
878
|
+
justifyContent: "center",
|
|
879
|
+
width: 36,
|
|
880
|
+
height: 36,
|
|
881
|
+
borderRadius: "var(--dauth-radius-sm, 8px)",
|
|
882
|
+
border: "none",
|
|
883
|
+
backgroundColor: "transparent",
|
|
884
|
+
color: "var(--dauth-text-secondary, #a1a1aa)",
|
|
885
|
+
cursor: "pointer",
|
|
886
|
+
transition: "background-color 150ms, color 150ms",
|
|
887
|
+
padding: 0
|
|
888
|
+
};
|
|
889
|
+
var bodyStyle = {
|
|
890
|
+
flex: 1,
|
|
891
|
+
overflowY: "auto",
|
|
892
|
+
padding: 24,
|
|
893
|
+
WebkitOverflowScrolling: "touch"
|
|
894
|
+
};
|
|
895
|
+
var avatarSection = {
|
|
896
|
+
display: "flex",
|
|
897
|
+
flexDirection: "column",
|
|
898
|
+
alignItems: "center",
|
|
899
|
+
marginBottom: 24,
|
|
900
|
+
gap: 8
|
|
901
|
+
};
|
|
902
|
+
var avatarCircle = {
|
|
903
|
+
width: 64,
|
|
904
|
+
height: 64,
|
|
905
|
+
borderRadius: "50%",
|
|
906
|
+
backgroundColor: "var(--dauth-accent, #6366f1)",
|
|
907
|
+
display: "flex",
|
|
908
|
+
alignItems: "center",
|
|
909
|
+
justifyContent: "center",
|
|
910
|
+
overflow: "hidden",
|
|
911
|
+
color: "#ffffff",
|
|
912
|
+
fontSize: "1.5rem",
|
|
913
|
+
fontWeight: 600
|
|
914
|
+
};
|
|
915
|
+
var emailText = {
|
|
916
|
+
fontSize: "var(--dauth-font-size-sm, 0.875rem)",
|
|
917
|
+
color: "var(--dauth-text-secondary, #a1a1aa)"
|
|
918
|
+
};
|
|
919
|
+
var statusMsg = (type) => ({
|
|
920
|
+
padding: "10px 14px",
|
|
921
|
+
borderRadius: "var(--dauth-radius-sm, 8px)",
|
|
922
|
+
fontSize: "var(--dauth-font-size-sm, 0.875rem)",
|
|
923
|
+
marginBottom: 16,
|
|
924
|
+
backgroundColor: type === "success" ? "var(--dauth-success-bg, rgba(34, 197, 94, 0.1))" : "var(--dauth-error-bg, rgba(239, 68, 68, 0.1))",
|
|
925
|
+
color: type === "success" ? "var(--dauth-success, #22c55e)" : "var(--dauth-error, #ef4444)",
|
|
926
|
+
textAlign: "center",
|
|
927
|
+
lineHeight: 1.5
|
|
928
|
+
});
|
|
929
|
+
var fieldGroup = { marginBottom: 16 };
|
|
930
|
+
var label = {
|
|
931
|
+
display: "block",
|
|
932
|
+
fontSize: "var(--dauth-font-size-sm, 0.875rem)",
|
|
933
|
+
fontWeight: 500,
|
|
934
|
+
color: "var(--dauth-text-primary, #e4e4e7)",
|
|
935
|
+
marginBottom: 6
|
|
936
|
+
};
|
|
937
|
+
var input = {
|
|
938
|
+
width: "100%",
|
|
939
|
+
padding: "10px 14px",
|
|
940
|
+
fontSize: "var(--dauth-font-size-base, 1rem)",
|
|
941
|
+
lineHeight: 1.5,
|
|
942
|
+
color: "var(--dauth-text-primary, #e4e4e7)",
|
|
943
|
+
backgroundColor: "var(--dauth-surface-secondary, rgba(255, 255, 255, 0.04))",
|
|
944
|
+
border: "1px solid var(--dauth-border, rgba(255, 255, 255, 0.08))",
|
|
945
|
+
borderRadius: "var(--dauth-radius-input, 8px)",
|
|
946
|
+
outline: "none",
|
|
947
|
+
transition: "border-color 150ms, box-shadow 150ms",
|
|
948
|
+
boxSizing: "border-box",
|
|
949
|
+
fontFamily: "inherit"
|
|
950
|
+
};
|
|
951
|
+
var inputFocusHandler = (e) => {
|
|
952
|
+
e.currentTarget.style.borderColor = "var(--dauth-border-focus, rgba(99, 102, 241, 0.5))";
|
|
953
|
+
e.currentTarget.style.boxShadow = "0 0 0 3px rgba(99, 102, 241, 0.15)";
|
|
954
|
+
};
|
|
955
|
+
var inputBlurHandler = (e) => {
|
|
956
|
+
e.currentTarget.style.borderColor = "var(--dauth-border, rgba(255, 255, 255, 0.08))";
|
|
957
|
+
e.currentTarget.style.boxShadow = "none";
|
|
958
|
+
};
|
|
959
|
+
var separator = {
|
|
960
|
+
height: 1,
|
|
961
|
+
backgroundColor: "var(--dauth-border, rgba(255, 255, 255, 0.08))",
|
|
962
|
+
margin: "24px 0",
|
|
963
|
+
border: "none"
|
|
964
|
+
};
|
|
965
|
+
var dangerTitle = {
|
|
966
|
+
fontSize: "var(--dauth-font-size-sm, 0.875rem)",
|
|
967
|
+
fontWeight: 600,
|
|
968
|
+
color: "var(--dauth-error, #ef4444)",
|
|
969
|
+
marginBottom: 4
|
|
970
|
+
};
|
|
971
|
+
var dangerDesc = {
|
|
972
|
+
fontSize: "var(--dauth-font-size-xs, 0.75rem)",
|
|
973
|
+
color: "var(--dauth-text-muted, #71717a)",
|
|
974
|
+
marginBottom: 12,
|
|
975
|
+
lineHeight: 1.5
|
|
976
|
+
};
|
|
977
|
+
var deleteBtn = {
|
|
978
|
+
padding: "8px 16px",
|
|
979
|
+
fontSize: "var(--dauth-font-size-sm, 0.875rem)",
|
|
980
|
+
fontWeight: 500,
|
|
981
|
+
color: "var(--dauth-error, #ef4444)",
|
|
982
|
+
backgroundColor: "var(--dauth-error-bg, rgba(239, 68, 68, 0.1))",
|
|
983
|
+
border: "1px solid rgba(239, 68, 68, 0.2)",
|
|
984
|
+
borderRadius: "var(--dauth-radius-sm, 8px)",
|
|
985
|
+
cursor: "pointer",
|
|
986
|
+
transition: "background-color 150ms, border-color 150ms",
|
|
987
|
+
fontFamily: "inherit"
|
|
988
|
+
};
|
|
989
|
+
var deletePanel = {
|
|
990
|
+
marginTop: 12,
|
|
991
|
+
padding: 16,
|
|
992
|
+
borderRadius: "var(--dauth-radius-sm, 8px)",
|
|
993
|
+
border: "1px solid rgba(239, 68, 68, 0.3)",
|
|
994
|
+
backgroundColor: "var(--dauth-error-bg, rgba(239, 68, 68, 0.1))"
|
|
995
|
+
};
|
|
996
|
+
var deletePanelText = {
|
|
997
|
+
fontSize: "var(--dauth-font-size-sm, 0.875rem)",
|
|
998
|
+
color: "var(--dauth-text-primary, #e4e4e7)",
|
|
999
|
+
marginBottom: 12,
|
|
1000
|
+
lineHeight: 1.5
|
|
1001
|
+
};
|
|
1002
|
+
var cancelBtn = {
|
|
1003
|
+
flex: 1,
|
|
1004
|
+
padding: "8px 16px",
|
|
1005
|
+
fontSize: "var(--dauth-font-size-sm, 0.875rem)",
|
|
1006
|
+
fontWeight: 500,
|
|
1007
|
+
color: "var(--dauth-text-secondary, #a1a1aa)",
|
|
1008
|
+
backgroundColor: "transparent",
|
|
1009
|
+
border: "1px solid var(--dauth-border, rgba(255, 255, 255, 0.08))",
|
|
1010
|
+
borderRadius: "var(--dauth-radius-sm, 8px)",
|
|
1011
|
+
cursor: "pointer",
|
|
1012
|
+
transition: "background-color 150ms",
|
|
1013
|
+
fontFamily: "inherit"
|
|
1014
|
+
};
|
|
1015
|
+
var deleteConfirmBtn = {
|
|
1016
|
+
flex: 1,
|
|
1017
|
+
padding: "8px 16px",
|
|
1018
|
+
fontSize: "var(--dauth-font-size-sm, 0.875rem)",
|
|
1019
|
+
fontWeight: 500,
|
|
1020
|
+
color: "#ffffff",
|
|
1021
|
+
backgroundColor: "var(--dauth-error, #ef4444)",
|
|
1022
|
+
border: "none",
|
|
1023
|
+
borderRadius: "var(--dauth-radius-sm, 8px)",
|
|
1024
|
+
cursor: "pointer",
|
|
1025
|
+
transition: "opacity 150ms",
|
|
1026
|
+
fontFamily: "inherit",
|
|
1027
|
+
display: "flex",
|
|
1028
|
+
alignItems: "center",
|
|
1029
|
+
justifyContent: "center",
|
|
1030
|
+
gap: 8
|
|
1031
|
+
};
|
|
1032
|
+
var footerStyle = (isDesktop) => ({
|
|
1033
|
+
padding: "16px 24px",
|
|
1034
|
+
borderTop: "1px solid var(--dauth-border, rgba(255, 255, 255, 0.08))",
|
|
1035
|
+
flexShrink: 0,
|
|
1036
|
+
...!isDesktop ? {
|
|
1037
|
+
position: "sticky",
|
|
1038
|
+
bottom: 0,
|
|
1039
|
+
zIndex: 1,
|
|
1040
|
+
backgroundColor: "var(--dauth-surface, #1a1a2e)",
|
|
1041
|
+
paddingBottom: "max(16px, env(safe-area-inset-bottom))"
|
|
1042
|
+
} : {}
|
|
1043
|
+
});
|
|
1044
|
+
var saveBtn = {
|
|
1045
|
+
width: "100%",
|
|
1046
|
+
padding: "12px 24px",
|
|
1047
|
+
fontSize: "var(--dauth-font-size-base, 1rem)",
|
|
1048
|
+
fontWeight: 600,
|
|
1049
|
+
color: "#ffffff",
|
|
1050
|
+
backgroundColor: "var(--dauth-accent, #6366f1)",
|
|
1051
|
+
border: "none",
|
|
1052
|
+
borderRadius: "var(--dauth-radius-sm, 8px)",
|
|
1053
|
+
transition: "opacity 150ms, background-color 150ms",
|
|
1054
|
+
display: "flex",
|
|
1055
|
+
alignItems: "center",
|
|
1056
|
+
justifyContent: "center",
|
|
1057
|
+
gap: 8,
|
|
1058
|
+
fontFamily: "inherit"
|
|
1059
|
+
};
|
|
1060
|
+
var spinnerStyle = {
|
|
1061
|
+
display: "inline-block",
|
|
1062
|
+
width: 16,
|
|
1063
|
+
height: 16,
|
|
1064
|
+
border: "2px solid rgba(255, 255, 255, 0.3)",
|
|
1065
|
+
borderTopColor: "#ffffff",
|
|
1066
|
+
borderRadius: "50%",
|
|
1067
|
+
animation: "dauth-spin 0.6s linear infinite"
|
|
1068
|
+
};
|
|
1069
|
+
|
|
342
1070
|
// src/index.tsx
|
|
343
|
-
import { jsx } from "react/jsx-runtime";
|
|
1071
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
344
1072
|
var defaultOnError = (error) => console.error(error);
|
|
345
1073
|
var DauthProvider = (props) => {
|
|
346
1074
|
const {
|
|
@@ -351,22 +1079,19 @@ var DauthProvider = (props) => {
|
|
|
351
1079
|
env,
|
|
352
1080
|
dauthUrl
|
|
353
1081
|
} = props;
|
|
354
|
-
const [dauthState, dispatch] = useReducer(
|
|
355
|
-
|
|
356
|
-
initialDauthState_default
|
|
357
|
-
);
|
|
358
|
-
useEffect(() => {
|
|
1082
|
+
const [dauthState, dispatch] = useReducer(userReducer, initialDauthState_default);
|
|
1083
|
+
useEffect2(() => {
|
|
359
1084
|
setDauthUrl(dauthUrl);
|
|
360
1085
|
}, [dauthUrl]);
|
|
361
|
-
const handleError =
|
|
1086
|
+
const handleError = useCallback2(
|
|
362
1087
|
(error) => (onError ?? defaultOnError)(error),
|
|
363
1088
|
[onError]
|
|
364
1089
|
);
|
|
365
|
-
const ctx =
|
|
1090
|
+
const ctx = useMemo2(
|
|
366
1091
|
() => ({ dispatch, authProxyPath, onError: handleError }),
|
|
367
1092
|
[authProxyPath, handleError]
|
|
368
1093
|
);
|
|
369
|
-
|
|
1094
|
+
useEffect2(() => {
|
|
370
1095
|
const params = new URLSearchParams(window.location.search);
|
|
371
1096
|
const code = params.get(AUTH_CODE_PARAM);
|
|
372
1097
|
if (code) {
|
|
@@ -375,16 +1100,13 @@ var DauthProvider = (props) => {
|
|
|
375
1100
|
autoLoginAction(ctx);
|
|
376
1101
|
}
|
|
377
1102
|
}, []);
|
|
378
|
-
const loginWithRedirect =
|
|
1103
|
+
const loginWithRedirect = useCallback2(() => {
|
|
379
1104
|
const base = `${getClientBasePath()}/${domainName}/${routes.signin}`;
|
|
380
1105
|
const url = env ? `${base}?env=${encodeURIComponent(env)}` : base;
|
|
381
1106
|
return window.location.replace(url);
|
|
382
1107
|
}, [domainName, env]);
|
|
383
|
-
const logout =
|
|
384
|
-
|
|
385
|
-
[ctx]
|
|
386
|
-
);
|
|
387
|
-
const updateUser = useCallback(
|
|
1108
|
+
const logout = useCallback2(() => logoutAction(ctx), [ctx]);
|
|
1109
|
+
const updateUser = useCallback2(
|
|
388
1110
|
async (fields) => {
|
|
389
1111
|
const {
|
|
390
1112
|
name,
|
|
@@ -414,33 +1136,21 @@ var DauthProvider = (props) => {
|
|
|
414
1136
|
},
|
|
415
1137
|
[ctx]
|
|
416
1138
|
);
|
|
417
|
-
const
|
|
418
|
-
() => updateUserWithRedirectAction(ctx),
|
|
419
|
-
[ctx]
|
|
420
|
-
);
|
|
421
|
-
const deleteAccount = useCallback(
|
|
1139
|
+
const deleteAccount = useCallback2(
|
|
422
1140
|
() => deleteAccountAction(ctx),
|
|
423
1141
|
[ctx]
|
|
424
1142
|
);
|
|
425
|
-
const memoProvider =
|
|
1143
|
+
const memoProvider = useMemo2(
|
|
426
1144
|
() => ({
|
|
427
1145
|
...dauthState,
|
|
428
1146
|
loginWithRedirect,
|
|
429
1147
|
logout,
|
|
430
1148
|
updateUser,
|
|
431
|
-
updateUserWithRedirect,
|
|
432
1149
|
deleteAccount
|
|
433
1150
|
}),
|
|
434
|
-
[
|
|
435
|
-
dauthState,
|
|
436
|
-
loginWithRedirect,
|
|
437
|
-
logout,
|
|
438
|
-
updateUser,
|
|
439
|
-
updateUserWithRedirect,
|
|
440
|
-
deleteAccount
|
|
441
|
-
]
|
|
1151
|
+
[dauthState, loginWithRedirect, logout, updateUser, deleteAccount]
|
|
442
1152
|
);
|
|
443
|
-
return /* @__PURE__ */
|
|
1153
|
+
return /* @__PURE__ */ jsx2(DauthContext.Provider, { value: memoProvider, children });
|
|
444
1154
|
};
|
|
445
1155
|
var DauthContext = createContext(initialDauthState_default);
|
|
446
1156
|
var useDauth = () => {
|
|
@@ -451,6 +1161,7 @@ var useDauth = () => {
|
|
|
451
1161
|
return context;
|
|
452
1162
|
};
|
|
453
1163
|
export {
|
|
1164
|
+
DauthProfileModal,
|
|
454
1165
|
DauthProvider,
|
|
455
1166
|
useDauth
|
|
456
1167
|
};
|