@thetechfossil/auth2 1.2.7 → 1.2.9
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 +141 -87
- package/dist/index.components.js.map +1 -1
- package/dist/index.components.mjs +141 -86
- package/dist/index.components.mjs.map +1 -1
- package/dist/index.d.ts +11 -0
- package/dist/index.js +141 -87
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +141 -86
- package/dist/index.mjs.map +1 -1
- package/dist/index.next.d.ts +11 -0
- package/dist/index.next.js +141 -88
- package/dist/index.next.js.map +1 -1
- package/dist/index.next.mjs +141 -87
- package/dist/index.next.mjs.map +1 -1
- package/package.json +9 -6
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import axios from 'axios';
|
|
3
|
-
import { UpfilesClient,
|
|
3
|
+
import { UpfilesClient, ImageManager } from '@thetechfossil/upfiles';
|
|
4
4
|
export { ConnectProjectDialog, ImageManager, ProjectFilesWidget, UpfilesClient, Uploader } from '@thetechfossil/upfiles';
|
|
5
5
|
import React3, { createContext, forwardRef, useContext, useState, useCallback, useEffect, useRef, useMemo } from 'react';
|
|
6
6
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
7
|
-
import PhoneInputWithCountry from 'react-phone-number-input';
|
|
8
|
-
import 'react-phone-number-input/style.css';
|
|
9
7
|
|
|
10
8
|
var __defProp = Object.defineProperty;
|
|
9
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
10
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
11
|
+
}) : x)(function(x) {
|
|
12
|
+
if (typeof require !== "undefined")
|
|
13
|
+
return require.apply(this, arguments);
|
|
14
|
+
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
15
|
+
});
|
|
11
16
|
var __export = (target, all) => {
|
|
12
17
|
for (var name in all)
|
|
13
18
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -1024,6 +1029,14 @@ function useThemeColors() {
|
|
|
1024
1029
|
const { theme } = useAuthTheme();
|
|
1025
1030
|
return theme === "dark" ? darkTheme : lightTheme;
|
|
1026
1031
|
}
|
|
1032
|
+
var PhoneInputWithCountry = null;
|
|
1033
|
+
try {
|
|
1034
|
+
const module = __require("react-phone-number-input");
|
|
1035
|
+
PhoneInputWithCountry = module.default || module;
|
|
1036
|
+
__require("react-phone-number-input/style.css");
|
|
1037
|
+
} catch (error) {
|
|
1038
|
+
console.warn("react-phone-number-input not available, using fallback");
|
|
1039
|
+
}
|
|
1027
1040
|
var CustomPhoneInput = React3.forwardRef((props, ref) => /* @__PURE__ */ jsx(
|
|
1028
1041
|
"input",
|
|
1029
1042
|
{
|
|
@@ -1216,6 +1229,30 @@ var PhoneInput = ({
|
|
|
1216
1229
|
const handleChange = useMemo(() => (val) => {
|
|
1217
1230
|
onChange(val || "");
|
|
1218
1231
|
}, [onChange]);
|
|
1232
|
+
if (!PhoneInputWithCountry) {
|
|
1233
|
+
return /* @__PURE__ */ jsx(
|
|
1234
|
+
"input",
|
|
1235
|
+
{
|
|
1236
|
+
id,
|
|
1237
|
+
type: "tel",
|
|
1238
|
+
value,
|
|
1239
|
+
onChange: (e) => onChange(e.target.value),
|
|
1240
|
+
disabled,
|
|
1241
|
+
required,
|
|
1242
|
+
placeholder,
|
|
1243
|
+
style: {
|
|
1244
|
+
width: "100%",
|
|
1245
|
+
padding: "12px 16px",
|
|
1246
|
+
border: `1px solid ${colors.borderSecondary}`,
|
|
1247
|
+
borderRadius: "8px",
|
|
1248
|
+
fontSize: "16px",
|
|
1249
|
+
backgroundColor: colors.bgSecondary,
|
|
1250
|
+
color: colors.textPrimary,
|
|
1251
|
+
...style
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
);
|
|
1255
|
+
}
|
|
1219
1256
|
return /* @__PURE__ */ jsxs(
|
|
1220
1257
|
"div",
|
|
1221
1258
|
{
|
|
@@ -4434,15 +4471,85 @@ var ChangePassword = ({ onSuccess, appearance }) => {
|
|
|
4434
4471
|
)
|
|
4435
4472
|
] }) });
|
|
4436
4473
|
};
|
|
4474
|
+
var AvatarUploader = ({
|
|
4475
|
+
onUploadComplete,
|
|
4476
|
+
onError,
|
|
4477
|
+
className,
|
|
4478
|
+
buttonClassName,
|
|
4479
|
+
maxFileSize = 5 * 1024 * 1024,
|
|
4480
|
+
// 5MB default
|
|
4481
|
+
upfilesConfig,
|
|
4482
|
+
buttonText = "Upload Avatar"
|
|
4483
|
+
}) => {
|
|
4484
|
+
const { uploadAndUpdateAvatar } = useAuth();
|
|
4485
|
+
const [open, setOpen] = useState(false);
|
|
4486
|
+
const [uploading, setUploading] = useState(false);
|
|
4487
|
+
const handleSelect = async (image) => {
|
|
4488
|
+
setUploading(true);
|
|
4489
|
+
try {
|
|
4490
|
+
const response = await fetch(image.url);
|
|
4491
|
+
const blob = await response.blob();
|
|
4492
|
+
const file = new File([blob], image.originalName, { type: image.contentType });
|
|
4493
|
+
const result = await uploadAndUpdateAvatar(file);
|
|
4494
|
+
if (result.success && result.user?.avatar) {
|
|
4495
|
+
onUploadComplete?.(result.user.avatar);
|
|
4496
|
+
setOpen(false);
|
|
4497
|
+
} else {
|
|
4498
|
+
throw new Error(result.message || "Failed to update avatar");
|
|
4499
|
+
}
|
|
4500
|
+
} catch (error) {
|
|
4501
|
+
const err = error instanceof Error ? error : new Error("Upload failed");
|
|
4502
|
+
onError?.(err);
|
|
4503
|
+
} finally {
|
|
4504
|
+
setUploading(false);
|
|
4505
|
+
}
|
|
4506
|
+
};
|
|
4507
|
+
return /* @__PURE__ */ jsxs("div", { className, children: [
|
|
4508
|
+
/* @__PURE__ */ jsx(
|
|
4509
|
+
"button",
|
|
4510
|
+
{
|
|
4511
|
+
type: "button",
|
|
4512
|
+
onClick: () => setOpen(true),
|
|
4513
|
+
disabled: uploading,
|
|
4514
|
+
className: buttonClassName || "px-4 py-2 text-sm rounded border bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50",
|
|
4515
|
+
children: uploading ? "Uploading..." : buttonText
|
|
4516
|
+
}
|
|
4517
|
+
),
|
|
4518
|
+
/* @__PURE__ */ jsx(
|
|
4519
|
+
ImageManager,
|
|
4520
|
+
{
|
|
4521
|
+
open,
|
|
4522
|
+
onOpenChange: setOpen,
|
|
4523
|
+
clientOptions: {
|
|
4524
|
+
baseUrl: upfilesConfig.baseUrl,
|
|
4525
|
+
apiKey: upfilesConfig.apiKey,
|
|
4526
|
+
apiKeyHeader: upfilesConfig.apiKeyHeader || "authorization",
|
|
4527
|
+
presignUrl: upfilesConfig.presignUrl,
|
|
4528
|
+
presignPath: upfilesConfig.presignPath
|
|
4529
|
+
},
|
|
4530
|
+
projectId: upfilesConfig.projectId,
|
|
4531
|
+
folderPath: upfilesConfig.folderPath || "avatars/",
|
|
4532
|
+
title: "Select Avatar",
|
|
4533
|
+
description: "Upload a new avatar or select from existing images.",
|
|
4534
|
+
mode: "full",
|
|
4535
|
+
maxFileSize,
|
|
4536
|
+
maxFiles: 1,
|
|
4537
|
+
autoRecordToDb: true,
|
|
4538
|
+
fetchThumbnails: true,
|
|
4539
|
+
onSelect: handleSelect
|
|
4540
|
+
}
|
|
4541
|
+
)
|
|
4542
|
+
] });
|
|
4543
|
+
};
|
|
4437
4544
|
var UserProfile = ({
|
|
4438
4545
|
showAvatar = true,
|
|
4439
4546
|
showEmailChange = true,
|
|
4440
|
-
showPasswordChange = true
|
|
4547
|
+
showPasswordChange = true,
|
|
4548
|
+
upfilesConfig
|
|
4441
4549
|
}) => {
|
|
4442
4550
|
const { user, updateProfile, requestEmailChange } = useAuth();
|
|
4443
4551
|
const colors = useThemeColors();
|
|
4444
4552
|
const [name, setName] = useState(user?.name || "");
|
|
4445
|
-
const [avatar, setAvatar] = useState(user?.avatar || "");
|
|
4446
4553
|
const [phoneNumber, setPhoneNumber] = useState(user?.phoneNumber || "");
|
|
4447
4554
|
const [newEmail, setNewEmail] = useState("");
|
|
4448
4555
|
const [isLoading, setIsLoading] = useState(false);
|
|
@@ -4458,9 +4565,6 @@ var UserProfile = ({
|
|
|
4458
4565
|
if (name !== user?.name) {
|
|
4459
4566
|
updates.name = name;
|
|
4460
4567
|
}
|
|
4461
|
-
if (showAvatar && avatar !== user?.avatar) {
|
|
4462
|
-
updates.avatar = avatar;
|
|
4463
|
-
}
|
|
4464
4568
|
if (phoneNumber !== user?.phoneNumber) {
|
|
4465
4569
|
updates.phoneNumber = phoneNumber;
|
|
4466
4570
|
}
|
|
@@ -4481,6 +4585,12 @@ var UserProfile = ({
|
|
|
4481
4585
|
setIsLoading(false);
|
|
4482
4586
|
}
|
|
4483
4587
|
};
|
|
4588
|
+
const handleAvatarUploadComplete = (avatarUrl) => {
|
|
4589
|
+
setSuccess("Avatar updated successfully!");
|
|
4590
|
+
};
|
|
4591
|
+
const handleAvatarUploadError = (error2) => {
|
|
4592
|
+
setError(error2.message || "Failed to upload avatar");
|
|
4593
|
+
};
|
|
4484
4594
|
const handleRequestEmailChange = async (e) => {
|
|
4485
4595
|
e.preventDefault();
|
|
4486
4596
|
setIsLoading(true);
|
|
@@ -4583,34 +4693,36 @@ var UserProfile = ({
|
|
|
4583
4693
|
}
|
|
4584
4694
|
)
|
|
4585
4695
|
] }),
|
|
4586
|
-
showAvatar && /* @__PURE__ */ jsxs("div", { style: { marginBottom: "20px" }, children: [
|
|
4587
|
-
/* @__PURE__ */ jsx("label", {
|
|
4696
|
+
showAvatar && upfilesConfig && /* @__PURE__ */ jsxs("div", { style: { marginBottom: "20px" }, children: [
|
|
4697
|
+
/* @__PURE__ */ jsx("label", { style: {
|
|
4588
4698
|
display: "block",
|
|
4589
4699
|
marginBottom: "8px",
|
|
4590
4700
|
fontWeight: 500,
|
|
4591
4701
|
color: colors.textSecondary,
|
|
4592
4702
|
fontSize: "14px"
|
|
4593
|
-
}, children: "Avatar
|
|
4594
|
-
/* @__PURE__ */ jsx(
|
|
4595
|
-
"
|
|
4703
|
+
}, children: "Avatar" }),
|
|
4704
|
+
user?.avatar && /* @__PURE__ */ jsx("div", { style: { marginBottom: "12px" }, children: /* @__PURE__ */ jsx(
|
|
4705
|
+
"img",
|
|
4596
4706
|
{
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
value: avatar,
|
|
4600
|
-
onChange: (e) => setAvatar(e.target.value),
|
|
4601
|
-
disabled: isLoading,
|
|
4707
|
+
src: user.avatar,
|
|
4708
|
+
alt: "Current avatar",
|
|
4602
4709
|
style: {
|
|
4603
|
-
width: "
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4710
|
+
width: "80px",
|
|
4711
|
+
height: "80px",
|
|
4712
|
+
borderRadius: "50%",
|
|
4713
|
+
objectFit: "cover",
|
|
4714
|
+
border: `2px solid ${colors.borderSecondary}`
|
|
4715
|
+
}
|
|
4716
|
+
}
|
|
4717
|
+
) }),
|
|
4718
|
+
/* @__PURE__ */ jsx(
|
|
4719
|
+
AvatarUploader,
|
|
4720
|
+
{
|
|
4721
|
+
upfilesConfig,
|
|
4722
|
+
onUploadComplete: handleAvatarUploadComplete,
|
|
4723
|
+
onError: handleAvatarUploadError,
|
|
4724
|
+
maxFileSize: 5 * 1024 * 1024,
|
|
4725
|
+
accept: ["image/*"]
|
|
4614
4726
|
}
|
|
4615
4727
|
)
|
|
4616
4728
|
] }),
|
|
@@ -4722,63 +4834,6 @@ var UserProfile = ({
|
|
|
4722
4834
|
] })
|
|
4723
4835
|
] });
|
|
4724
4836
|
};
|
|
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
4837
|
var AvatarManager = ({
|
|
4783
4838
|
open,
|
|
4784
4839
|
onOpenChange,
|