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