@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.components.d.ts +11 -0
- package/dist/index.components.js +101 -84
- package/dist/index.components.js.map +1 -1
- package/dist/index.components.mjs +102 -85
- package/dist/index.components.mjs.map +1 -1
- package/dist/index.d.ts +11 -0
- package/dist/index.js +101 -84
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +102 -85
- package/dist/index.mjs.map +1 -1
- package/dist/index.next.d.ts +11 -0
- package/dist/index.next.js +101 -84
- package/dist/index.next.js.map +1 -1
- package/dist/index.next.mjs +102 -85
- package/dist/index.next.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/index.next.server.d.ts +0 -272
package/dist/index.d.ts
CHANGED
|
@@ -414,6 +414,15 @@ interface UserProfileProps {
|
|
|
414
414
|
showAvatar?: boolean;
|
|
415
415
|
showEmailChange?: boolean;
|
|
416
416
|
showPasswordChange?: boolean;
|
|
417
|
+
upfilesConfig?: {
|
|
418
|
+
baseUrl: string;
|
|
419
|
+
apiKey?: string;
|
|
420
|
+
apiKeyHeader?: 'authorization' | 'x-api-key' | 'x-up-api-key';
|
|
421
|
+
presignUrl?: string;
|
|
422
|
+
presignPath?: string;
|
|
423
|
+
folderPath?: string;
|
|
424
|
+
projectId?: string;
|
|
425
|
+
};
|
|
417
426
|
}
|
|
418
427
|
declare const UserProfile: React.FC<UserProfileProps>;
|
|
419
428
|
|
|
@@ -443,7 +452,9 @@ interface AvatarUploaderProps {
|
|
|
443
452
|
presignUrl?: string;
|
|
444
453
|
presignPath?: string;
|
|
445
454
|
folderPath?: string;
|
|
455
|
+
projectId?: string;
|
|
446
456
|
};
|
|
457
|
+
buttonText?: string;
|
|
447
458
|
}
|
|
448
459
|
declare const AvatarUploader: React.FC<AvatarUploaderProps>;
|
|
449
460
|
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use client";
|
|
2
1
|
'use strict';
|
|
3
2
|
|
|
4
3
|
var axios = require('axios');
|
|
@@ -4441,15 +4440,85 @@ var ChangePassword = ({ onSuccess, appearance }) => {
|
|
|
4441
4440
|
)
|
|
4442
4441
|
] }) });
|
|
4443
4442
|
};
|
|
4443
|
+
var AvatarUploader = ({
|
|
4444
|
+
onUploadComplete,
|
|
4445
|
+
onError,
|
|
4446
|
+
className,
|
|
4447
|
+
buttonClassName,
|
|
4448
|
+
maxFileSize = 5 * 1024 * 1024,
|
|
4449
|
+
// 5MB default
|
|
4450
|
+
upfilesConfig,
|
|
4451
|
+
buttonText = "Upload Avatar"
|
|
4452
|
+
}) => {
|
|
4453
|
+
const { uploadAndUpdateAvatar } = useAuth();
|
|
4454
|
+
const [open, setOpen] = React3.useState(false);
|
|
4455
|
+
const [uploading, setUploading] = React3.useState(false);
|
|
4456
|
+
const handleSelect = async (image) => {
|
|
4457
|
+
setUploading(true);
|
|
4458
|
+
try {
|
|
4459
|
+
const response = await fetch(image.url);
|
|
4460
|
+
const blob = await response.blob();
|
|
4461
|
+
const file = new File([blob], image.originalName, { type: image.contentType });
|
|
4462
|
+
const result = await uploadAndUpdateAvatar(file);
|
|
4463
|
+
if (result.success && result.user?.avatar) {
|
|
4464
|
+
onUploadComplete?.(result.user.avatar);
|
|
4465
|
+
setOpen(false);
|
|
4466
|
+
} else {
|
|
4467
|
+
throw new Error(result.message || "Failed to update avatar");
|
|
4468
|
+
}
|
|
4469
|
+
} catch (error) {
|
|
4470
|
+
const err = error instanceof Error ? error : new Error("Upload failed");
|
|
4471
|
+
onError?.(err);
|
|
4472
|
+
} finally {
|
|
4473
|
+
setUploading(false);
|
|
4474
|
+
}
|
|
4475
|
+
};
|
|
4476
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, children: [
|
|
4477
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4478
|
+
"button",
|
|
4479
|
+
{
|
|
4480
|
+
type: "button",
|
|
4481
|
+
onClick: () => setOpen(true),
|
|
4482
|
+
disabled: uploading,
|
|
4483
|
+
className: buttonClassName || "px-4 py-2 text-sm rounded border bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50",
|
|
4484
|
+
children: uploading ? "Uploading..." : buttonText
|
|
4485
|
+
}
|
|
4486
|
+
),
|
|
4487
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4488
|
+
upfiles.ImageManager,
|
|
4489
|
+
{
|
|
4490
|
+
open,
|
|
4491
|
+
onOpenChange: setOpen,
|
|
4492
|
+
clientOptions: {
|
|
4493
|
+
baseUrl: upfilesConfig.baseUrl,
|
|
4494
|
+
apiKey: upfilesConfig.apiKey,
|
|
4495
|
+
apiKeyHeader: upfilesConfig.apiKeyHeader || "authorization",
|
|
4496
|
+
presignUrl: upfilesConfig.presignUrl,
|
|
4497
|
+
presignPath: upfilesConfig.presignPath
|
|
4498
|
+
},
|
|
4499
|
+
projectId: upfilesConfig.projectId,
|
|
4500
|
+
folderPath: upfilesConfig.folderPath || "avatars/",
|
|
4501
|
+
title: "Select Avatar",
|
|
4502
|
+
description: "Upload a new avatar or select from existing images.",
|
|
4503
|
+
mode: "full",
|
|
4504
|
+
maxFileSize,
|
|
4505
|
+
maxFiles: 1,
|
|
4506
|
+
autoRecordToDb: true,
|
|
4507
|
+
fetchThumbnails: true,
|
|
4508
|
+
onSelect: handleSelect
|
|
4509
|
+
}
|
|
4510
|
+
)
|
|
4511
|
+
] });
|
|
4512
|
+
};
|
|
4444
4513
|
var UserProfile = ({
|
|
4445
4514
|
showAvatar = true,
|
|
4446
4515
|
showEmailChange = true,
|
|
4447
|
-
showPasswordChange = true
|
|
4516
|
+
showPasswordChange = true,
|
|
4517
|
+
upfilesConfig
|
|
4448
4518
|
}) => {
|
|
4449
4519
|
const { user, updateProfile, requestEmailChange } = useAuth();
|
|
4450
4520
|
const colors = useThemeColors();
|
|
4451
4521
|
const [name, setName] = React3.useState(user?.name || "");
|
|
4452
|
-
const [avatar, setAvatar] = React3.useState(user?.avatar || "");
|
|
4453
4522
|
const [phoneNumber, setPhoneNumber] = React3.useState(user?.phoneNumber || "");
|
|
4454
4523
|
const [newEmail, setNewEmail] = React3.useState("");
|
|
4455
4524
|
const [isLoading, setIsLoading] = React3.useState(false);
|
|
@@ -4465,9 +4534,6 @@ var UserProfile = ({
|
|
|
4465
4534
|
if (name !== user?.name) {
|
|
4466
4535
|
updates.name = name;
|
|
4467
4536
|
}
|
|
4468
|
-
if (showAvatar && avatar !== user?.avatar) {
|
|
4469
|
-
updates.avatar = avatar;
|
|
4470
|
-
}
|
|
4471
4537
|
if (phoneNumber !== user?.phoneNumber) {
|
|
4472
4538
|
updates.phoneNumber = phoneNumber;
|
|
4473
4539
|
}
|
|
@@ -4488,6 +4554,12 @@ var UserProfile = ({
|
|
|
4488
4554
|
setIsLoading(false);
|
|
4489
4555
|
}
|
|
4490
4556
|
};
|
|
4557
|
+
const handleAvatarUploadComplete = (avatarUrl) => {
|
|
4558
|
+
setSuccess("Avatar updated successfully!");
|
|
4559
|
+
};
|
|
4560
|
+
const handleAvatarUploadError = (error2) => {
|
|
4561
|
+
setError(error2.message || "Failed to upload avatar");
|
|
4562
|
+
};
|
|
4491
4563
|
const handleRequestEmailChange = async (e) => {
|
|
4492
4564
|
e.preventDefault();
|
|
4493
4565
|
setIsLoading(true);
|
|
@@ -4590,34 +4662,36 @@ var UserProfile = ({
|
|
|
4590
4662
|
}
|
|
4591
4663
|
)
|
|
4592
4664
|
] }),
|
|
4593
|
-
showAvatar && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
|
|
4594
|
-
/* @__PURE__ */ jsxRuntime.jsx("label", {
|
|
4665
|
+
showAvatar && upfilesConfig && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
|
|
4666
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { style: {
|
|
4595
4667
|
display: "block",
|
|
4596
4668
|
marginBottom: "8px",
|
|
4597
4669
|
fontWeight: 500,
|
|
4598
4670
|
color: colors.textSecondary,
|
|
4599
4671
|
fontSize: "14px"
|
|
4600
|
-
}, children: "Avatar
|
|
4601
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4602
|
-
"
|
|
4672
|
+
}, children: "Avatar" }),
|
|
4673
|
+
user?.avatar && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginBottom: "12px" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4674
|
+
"img",
|
|
4603
4675
|
{
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
value: avatar,
|
|
4607
|
-
onChange: (e) => setAvatar(e.target.value),
|
|
4608
|
-
disabled: isLoading,
|
|
4676
|
+
src: user.avatar,
|
|
4677
|
+
alt: "Current avatar",
|
|
4609
4678
|
style: {
|
|
4610
|
-
width: "
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4679
|
+
width: "80px",
|
|
4680
|
+
height: "80px",
|
|
4681
|
+
borderRadius: "50%",
|
|
4682
|
+
objectFit: "cover",
|
|
4683
|
+
border: `2px solid ${colors.borderSecondary}`
|
|
4684
|
+
}
|
|
4685
|
+
}
|
|
4686
|
+
) }),
|
|
4687
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4688
|
+
AvatarUploader,
|
|
4689
|
+
{
|
|
4690
|
+
upfilesConfig,
|
|
4691
|
+
onUploadComplete: handleAvatarUploadComplete,
|
|
4692
|
+
onError: handleAvatarUploadError,
|
|
4693
|
+
maxFileSize: 5 * 1024 * 1024,
|
|
4694
|
+
accept: ["image/*"]
|
|
4621
4695
|
}
|
|
4622
4696
|
)
|
|
4623
4697
|
] }),
|
|
@@ -4729,63 +4803,6 @@ var UserProfile = ({
|
|
|
4729
4803
|
] })
|
|
4730
4804
|
] });
|
|
4731
4805
|
};
|
|
4732
|
-
var AvatarUploader = ({
|
|
4733
|
-
onUploadComplete,
|
|
4734
|
-
onError,
|
|
4735
|
-
className,
|
|
4736
|
-
buttonClassName,
|
|
4737
|
-
dropzoneClassName,
|
|
4738
|
-
maxFileSize = 5 * 1024 * 1024,
|
|
4739
|
-
// 5MB default
|
|
4740
|
-
accept = ["image/*"],
|
|
4741
|
-
upfilesConfig
|
|
4742
|
-
}) => {
|
|
4743
|
-
const { uploadAndUpdateAvatar } = useAuth();
|
|
4744
|
-
const [uploading, setUploading] = React3.useState(false);
|
|
4745
|
-
const handleUploadComplete = async (files) => {
|
|
4746
|
-
if (files.length === 0)
|
|
4747
|
-
return;
|
|
4748
|
-
setUploading(true);
|
|
4749
|
-
try {
|
|
4750
|
-
const file = files[0];
|
|
4751
|
-
const response = await uploadAndUpdateAvatar(file.file);
|
|
4752
|
-
if (response.success && response.user?.avatar) {
|
|
4753
|
-
onUploadComplete?.(response.user.avatar);
|
|
4754
|
-
} else {
|
|
4755
|
-
throw new Error(response.message || "Failed to update avatar");
|
|
4756
|
-
}
|
|
4757
|
-
} catch (error) {
|
|
4758
|
-
const err = error instanceof Error ? error : new Error("Upload failed");
|
|
4759
|
-
onError?.(err);
|
|
4760
|
-
} finally {
|
|
4761
|
-
setUploading(false);
|
|
4762
|
-
}
|
|
4763
|
-
};
|
|
4764
|
-
const handleError = (error) => {
|
|
4765
|
-
onError?.(error);
|
|
4766
|
-
};
|
|
4767
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", { className, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4768
|
-
upfiles.Uploader,
|
|
4769
|
-
{
|
|
4770
|
-
clientOptions: {
|
|
4771
|
-
baseUrl: upfilesConfig.baseUrl,
|
|
4772
|
-
apiKey: upfilesConfig.apiKey,
|
|
4773
|
-
apiKeyHeader: upfilesConfig.apiKeyHeader || "authorization",
|
|
4774
|
-
presignUrl: upfilesConfig.presignUrl,
|
|
4775
|
-
presignPath: upfilesConfig.presignPath
|
|
4776
|
-
},
|
|
4777
|
-
multiple: false,
|
|
4778
|
-
accept,
|
|
4779
|
-
maxFileSize,
|
|
4780
|
-
maxFiles: 1,
|
|
4781
|
-
onComplete: handleUploadComplete,
|
|
4782
|
-
onError: handleError,
|
|
4783
|
-
buttonClassName,
|
|
4784
|
-
dropzoneClassName,
|
|
4785
|
-
children: uploading ? "Uploading..." : "Upload Avatar"
|
|
4786
|
-
}
|
|
4787
|
-
) });
|
|
4788
|
-
};
|
|
4789
4806
|
var AvatarManager = ({
|
|
4790
4807
|
open,
|
|
4791
4808
|
onOpenChange,
|