@thetechfossil/auth2 1.2.17 → 1.2.18

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.
@@ -4521,6 +4521,34 @@ var injectModalStyles = () => {
4521
4521
  `;
4522
4522
  document.head.appendChild(styleElement);
4523
4523
  };
4524
+
4525
+ // src/react/components/utils/getAnonymousUserId.ts
4526
+ var ANONYMOUS_USER_ID_KEY = "ttf_auth_anonymous_user_id";
4527
+ function generateUUID() {
4528
+ if (typeof crypto !== "undefined" && crypto.randomUUID) {
4529
+ return crypto.randomUUID();
4530
+ }
4531
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
4532
+ const r = Math.random() * 16 | 0;
4533
+ const v = c === "x" ? r : r & 3 | 8;
4534
+ return v.toString(16);
4535
+ });
4536
+ }
4537
+ function getAnonymousUserId() {
4538
+ if (typeof window === "undefined" || typeof localStorage === "undefined") {
4539
+ return null;
4540
+ }
4541
+ try {
4542
+ let anonymousId = localStorage.getItem(ANONYMOUS_USER_ID_KEY);
4543
+ if (!anonymousId) {
4544
+ anonymousId = generateUUID();
4545
+ localStorage.setItem(ANONYMOUS_USER_ID_KEY, anonymousId);
4546
+ }
4547
+ return anonymousId;
4548
+ } catch {
4549
+ return generateUUID();
4550
+ }
4551
+ }
4524
4552
  var AvatarUploader = ({
4525
4553
  onUploadComplete,
4526
4554
  onError,
@@ -4541,6 +4569,10 @@ var AvatarUploader = ({
4541
4569
  if (user?.id) {
4542
4570
  return `users/${user.id}/`;
4543
4571
  }
4572
+ const anonymousId = getAnonymousUserId();
4573
+ if (anonymousId) {
4574
+ return `anonymous/${anonymousId}/`;
4575
+ }
4544
4576
  return upfilesConfig.folderPath || "/";
4545
4577
  }, [user?.id, upfilesConfig.folderPath]);
4546
4578
  const handleSelect = async (image) => {
@@ -4920,6 +4952,10 @@ var AvatarManager = ({
4920
4952
  if (user?.id) {
4921
4953
  return `users/${user.id}/`;
4922
4954
  }
4955
+ const anonymousId = getAnonymousUserId();
4956
+ if (anonymousId) {
4957
+ return `anonymous/${anonymousId}/`;
4958
+ }
4923
4959
  return upfilesConfig.folderPath || "/";
4924
4960
  }, [user?.id, upfilesConfig.folderPath]);
4925
4961
  const handleSelect = async (image) => {