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