@thetechfossil/auth2 1.2.7 → 1.2.8

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 CHANGED
@@ -1,6 +1,5 @@
1
- "use client";
2
1
  import axios from 'axios';
3
- import { UpfilesClient, Uploader, ImageManager } from '@thetechfossil/upfiles';
2
+ import { UpfilesClient, ImageManager } from '@thetechfossil/upfiles';
4
3
  export { ConnectProjectDialog, ImageManager, ProjectFilesWidget, UpfilesClient, Uploader } from '@thetechfossil/upfiles';
5
4
  import React3, { createContext, forwardRef, useContext, useState, useCallback, useEffect, useRef, useMemo } from 'react';
6
5
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
@@ -4434,15 +4433,85 @@ var ChangePassword = ({ onSuccess, appearance }) => {
4434
4433
  )
4435
4434
  ] }) });
4436
4435
  };
4436
+ var AvatarUploader = ({
4437
+ onUploadComplete,
4438
+ onError,
4439
+ className,
4440
+ buttonClassName,
4441
+ maxFileSize = 5 * 1024 * 1024,
4442
+ // 5MB default
4443
+ upfilesConfig,
4444
+ buttonText = "Upload Avatar"
4445
+ }) => {
4446
+ const { uploadAndUpdateAvatar } = useAuth();
4447
+ const [open, setOpen] = useState(false);
4448
+ const [uploading, setUploading] = useState(false);
4449
+ const handleSelect = async (image) => {
4450
+ setUploading(true);
4451
+ try {
4452
+ const response = await fetch(image.url);
4453
+ const blob = await response.blob();
4454
+ const file = new File([blob], image.originalName, { type: image.contentType });
4455
+ const result = await uploadAndUpdateAvatar(file);
4456
+ if (result.success && result.user?.avatar) {
4457
+ onUploadComplete?.(result.user.avatar);
4458
+ setOpen(false);
4459
+ } else {
4460
+ throw new Error(result.message || "Failed to update avatar");
4461
+ }
4462
+ } catch (error) {
4463
+ const err = error instanceof Error ? error : new Error("Upload failed");
4464
+ onError?.(err);
4465
+ } finally {
4466
+ setUploading(false);
4467
+ }
4468
+ };
4469
+ return /* @__PURE__ */ jsxs("div", { className, children: [
4470
+ /* @__PURE__ */ jsx(
4471
+ "button",
4472
+ {
4473
+ type: "button",
4474
+ onClick: () => setOpen(true),
4475
+ disabled: uploading,
4476
+ className: buttonClassName || "px-4 py-2 text-sm rounded border bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50",
4477
+ children: uploading ? "Uploading..." : buttonText
4478
+ }
4479
+ ),
4480
+ /* @__PURE__ */ jsx(
4481
+ ImageManager,
4482
+ {
4483
+ open,
4484
+ onOpenChange: setOpen,
4485
+ clientOptions: {
4486
+ baseUrl: upfilesConfig.baseUrl,
4487
+ apiKey: upfilesConfig.apiKey,
4488
+ apiKeyHeader: upfilesConfig.apiKeyHeader || "authorization",
4489
+ presignUrl: upfilesConfig.presignUrl,
4490
+ presignPath: upfilesConfig.presignPath
4491
+ },
4492
+ projectId: upfilesConfig.projectId,
4493
+ folderPath: upfilesConfig.folderPath || "avatars/",
4494
+ title: "Select Avatar",
4495
+ description: "Upload a new avatar or select from existing images.",
4496
+ mode: "full",
4497
+ maxFileSize,
4498
+ maxFiles: 1,
4499
+ autoRecordToDb: true,
4500
+ fetchThumbnails: true,
4501
+ onSelect: handleSelect
4502
+ }
4503
+ )
4504
+ ] });
4505
+ };
4437
4506
  var UserProfile = ({
4438
4507
  showAvatar = true,
4439
4508
  showEmailChange = true,
4440
- showPasswordChange = true
4509
+ showPasswordChange = true,
4510
+ upfilesConfig
4441
4511
  }) => {
4442
4512
  const { user, updateProfile, requestEmailChange } = useAuth();
4443
4513
  const colors = useThemeColors();
4444
4514
  const [name, setName] = useState(user?.name || "");
4445
- const [avatar, setAvatar] = useState(user?.avatar || "");
4446
4515
  const [phoneNumber, setPhoneNumber] = useState(user?.phoneNumber || "");
4447
4516
  const [newEmail, setNewEmail] = useState("");
4448
4517
  const [isLoading, setIsLoading] = useState(false);
@@ -4458,9 +4527,6 @@ var UserProfile = ({
4458
4527
  if (name !== user?.name) {
4459
4528
  updates.name = name;
4460
4529
  }
4461
- if (showAvatar && avatar !== user?.avatar) {
4462
- updates.avatar = avatar;
4463
- }
4464
4530
  if (phoneNumber !== user?.phoneNumber) {
4465
4531
  updates.phoneNumber = phoneNumber;
4466
4532
  }
@@ -4481,6 +4547,12 @@ var UserProfile = ({
4481
4547
  setIsLoading(false);
4482
4548
  }
4483
4549
  };
4550
+ const handleAvatarUploadComplete = (avatarUrl) => {
4551
+ setSuccess("Avatar updated successfully!");
4552
+ };
4553
+ const handleAvatarUploadError = (error2) => {
4554
+ setError(error2.message || "Failed to upload avatar");
4555
+ };
4484
4556
  const handleRequestEmailChange = async (e) => {
4485
4557
  e.preventDefault();
4486
4558
  setIsLoading(true);
@@ -4583,34 +4655,36 @@ var UserProfile = ({
4583
4655
  }
4584
4656
  )
4585
4657
  ] }),
4586
- showAvatar && /* @__PURE__ */ jsxs("div", { style: { marginBottom: "20px" }, children: [
4587
- /* @__PURE__ */ jsx("label", { htmlFor: "avatar", style: {
4658
+ showAvatar && upfilesConfig && /* @__PURE__ */ jsxs("div", { style: { marginBottom: "20px" }, children: [
4659
+ /* @__PURE__ */ jsx("label", { style: {
4588
4660
  display: "block",
4589
4661
  marginBottom: "8px",
4590
4662
  fontWeight: 500,
4591
4663
  color: colors.textSecondary,
4592
4664
  fontSize: "14px"
4593
- }, children: "Avatar URL" }),
4594
- /* @__PURE__ */ jsx(
4595
- "input",
4665
+ }, children: "Avatar" }),
4666
+ user?.avatar && /* @__PURE__ */ jsx("div", { style: { marginBottom: "12px" }, children: /* @__PURE__ */ jsx(
4667
+ "img",
4596
4668
  {
4597
- id: "avatar",
4598
- type: "url",
4599
- value: avatar,
4600
- onChange: (e) => setAvatar(e.target.value),
4601
- disabled: isLoading,
4669
+ src: user.avatar,
4670
+ alt: "Current avatar",
4602
4671
  style: {
4603
- width: "100%",
4604
- padding: "12px 16px",
4605
- border: `1px solid ${colors.borderSecondary}`,
4606
- borderRadius: "8px",
4607
- fontSize: "16px",
4608
- boxSizing: "border-box",
4609
- backgroundColor: colors.bgSecondary,
4610
- color: colors.textPrimary,
4611
- transition: "all 0.2s ease"
4612
- },
4613
- placeholder: "https://example.com/avatar.jpg"
4672
+ width: "80px",
4673
+ height: "80px",
4674
+ borderRadius: "50%",
4675
+ objectFit: "cover",
4676
+ border: `2px solid ${colors.borderSecondary}`
4677
+ }
4678
+ }
4679
+ ) }),
4680
+ /* @__PURE__ */ jsx(
4681
+ AvatarUploader,
4682
+ {
4683
+ upfilesConfig,
4684
+ onUploadComplete: handleAvatarUploadComplete,
4685
+ onError: handleAvatarUploadError,
4686
+ maxFileSize: 5 * 1024 * 1024,
4687
+ accept: ["image/*"]
4614
4688
  }
4615
4689
  )
4616
4690
  ] }),
@@ -4722,63 +4796,6 @@ var UserProfile = ({
4722
4796
  ] })
4723
4797
  ] });
4724
4798
  };
4725
- var AvatarUploader = ({
4726
- onUploadComplete,
4727
- onError,
4728
- className,
4729
- buttonClassName,
4730
- dropzoneClassName,
4731
- maxFileSize = 5 * 1024 * 1024,
4732
- // 5MB default
4733
- accept = ["image/*"],
4734
- upfilesConfig
4735
- }) => {
4736
- const { uploadAndUpdateAvatar } = useAuth();
4737
- const [uploading, setUploading] = useState(false);
4738
- const handleUploadComplete = async (files) => {
4739
- if (files.length === 0)
4740
- return;
4741
- setUploading(true);
4742
- try {
4743
- const file = files[0];
4744
- const response = await uploadAndUpdateAvatar(file.file);
4745
- if (response.success && response.user?.avatar) {
4746
- onUploadComplete?.(response.user.avatar);
4747
- } else {
4748
- throw new Error(response.message || "Failed to update avatar");
4749
- }
4750
- } catch (error) {
4751
- const err = error instanceof Error ? error : new Error("Upload failed");
4752
- onError?.(err);
4753
- } finally {
4754
- setUploading(false);
4755
- }
4756
- };
4757
- const handleError = (error) => {
4758
- onError?.(error);
4759
- };
4760
- return /* @__PURE__ */ jsx("div", { className, children: /* @__PURE__ */ jsx(
4761
- Uploader,
4762
- {
4763
- clientOptions: {
4764
- baseUrl: upfilesConfig.baseUrl,
4765
- apiKey: upfilesConfig.apiKey,
4766
- apiKeyHeader: upfilesConfig.apiKeyHeader || "authorization",
4767
- presignUrl: upfilesConfig.presignUrl,
4768
- presignPath: upfilesConfig.presignPath
4769
- },
4770
- multiple: false,
4771
- accept,
4772
- maxFileSize,
4773
- maxFiles: 1,
4774
- onComplete: handleUploadComplete,
4775
- onError: handleError,
4776
- buttonClassName,
4777
- dropzoneClassName,
4778
- children: uploading ? "Uploading..." : "Upload Avatar"
4779
- }
4780
- ) });
4781
- };
4782
4799
  var AvatarManager = ({
4783
4800
  open,
4784
4801
  onOpenChange,