@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.
@@ -177,6 +177,15 @@ interface UserProfileProps {
177
177
  showAvatar?: boolean;
178
178
  showEmailChange?: boolean;
179
179
  showPasswordChange?: boolean;
180
+ upfilesConfig?: {
181
+ baseUrl: string;
182
+ apiKey?: string;
183
+ apiKeyHeader?: 'authorization' | 'x-api-key' | 'x-up-api-key';
184
+ presignUrl?: string;
185
+ presignPath?: string;
186
+ folderPath?: string;
187
+ projectId?: string;
188
+ };
180
189
  }
181
190
  declare const UserProfile: React.FC<UserProfileProps>;
182
191
 
@@ -206,7 +215,9 @@ interface AvatarUploaderProps {
206
215
  presignUrl?: string;
207
216
  presignPath?: string;
208
217
  folderPath?: string;
218
+ projectId?: string;
209
219
  };
220
+ buttonText?: string;
210
221
  }
211
222
  declare const AvatarUploader: React.FC<AvatarUploaderProps>;
212
223
 
@@ -1,4 +1,3 @@
1
- "use client";
2
1
  'use strict';
3
2
 
4
3
  var React2 = require('react');
@@ -4113,15 +4112,85 @@ var ChangePassword = ({ onSuccess, appearance }) => {
4113
4112
  )
4114
4113
  ] }) });
4115
4114
  };
4115
+ var AvatarUploader = ({
4116
+ onUploadComplete,
4117
+ onError,
4118
+ className,
4119
+ buttonClassName,
4120
+ maxFileSize = 5 * 1024 * 1024,
4121
+ // 5MB default
4122
+ upfilesConfig,
4123
+ buttonText = "Upload Avatar"
4124
+ }) => {
4125
+ const { uploadAndUpdateAvatar } = useAuth2();
4126
+ const [open, setOpen] = React2.useState(false);
4127
+ const [uploading, setUploading] = React2.useState(false);
4128
+ const handleSelect = async (image) => {
4129
+ setUploading(true);
4130
+ try {
4131
+ const response = await fetch(image.url);
4132
+ const blob = await response.blob();
4133
+ const file = new File([blob], image.originalName, { type: image.contentType });
4134
+ const result = await uploadAndUpdateAvatar(file);
4135
+ if (result.success && result.user?.avatar) {
4136
+ onUploadComplete?.(result.user.avatar);
4137
+ setOpen(false);
4138
+ } else {
4139
+ throw new Error(result.message || "Failed to update avatar");
4140
+ }
4141
+ } catch (error) {
4142
+ const err = error instanceof Error ? error : new Error("Upload failed");
4143
+ onError?.(err);
4144
+ } finally {
4145
+ setUploading(false);
4146
+ }
4147
+ };
4148
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, children: [
4149
+ /* @__PURE__ */ jsxRuntime.jsx(
4150
+ "button",
4151
+ {
4152
+ type: "button",
4153
+ onClick: () => setOpen(true),
4154
+ disabled: uploading,
4155
+ className: buttonClassName || "px-4 py-2 text-sm rounded border bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50",
4156
+ children: uploading ? "Uploading..." : buttonText
4157
+ }
4158
+ ),
4159
+ /* @__PURE__ */ jsxRuntime.jsx(
4160
+ upfiles.ImageManager,
4161
+ {
4162
+ open,
4163
+ onOpenChange: setOpen,
4164
+ clientOptions: {
4165
+ baseUrl: upfilesConfig.baseUrl,
4166
+ apiKey: upfilesConfig.apiKey,
4167
+ apiKeyHeader: upfilesConfig.apiKeyHeader || "authorization",
4168
+ presignUrl: upfilesConfig.presignUrl,
4169
+ presignPath: upfilesConfig.presignPath
4170
+ },
4171
+ projectId: upfilesConfig.projectId,
4172
+ folderPath: upfilesConfig.folderPath || "avatars/",
4173
+ title: "Select Avatar",
4174
+ description: "Upload a new avatar or select from existing images.",
4175
+ mode: "full",
4176
+ maxFileSize,
4177
+ maxFiles: 1,
4178
+ autoRecordToDb: true,
4179
+ fetchThumbnails: true,
4180
+ onSelect: handleSelect
4181
+ }
4182
+ )
4183
+ ] });
4184
+ };
4116
4185
  var UserProfile = ({
4117
4186
  showAvatar = true,
4118
4187
  showEmailChange = true,
4119
- showPasswordChange = true
4188
+ showPasswordChange = true,
4189
+ upfilesConfig
4120
4190
  }) => {
4121
4191
  const { user, updateProfile, requestEmailChange } = useAuth2();
4122
4192
  const colors = useThemeColors();
4123
4193
  const [name, setName] = React2.useState(user?.name || "");
4124
- const [avatar, setAvatar] = React2.useState(user?.avatar || "");
4125
4194
  const [phoneNumber, setPhoneNumber] = React2.useState(user?.phoneNumber || "");
4126
4195
  const [newEmail, setNewEmail] = React2.useState("");
4127
4196
  const [isLoading, setIsLoading] = React2.useState(false);
@@ -4137,9 +4206,6 @@ var UserProfile = ({
4137
4206
  if (name !== user?.name) {
4138
4207
  updates.name = name;
4139
4208
  }
4140
- if (showAvatar && avatar !== user?.avatar) {
4141
- updates.avatar = avatar;
4142
- }
4143
4209
  if (phoneNumber !== user?.phoneNumber) {
4144
4210
  updates.phoneNumber = phoneNumber;
4145
4211
  }
@@ -4160,6 +4226,12 @@ var UserProfile = ({
4160
4226
  setIsLoading(false);
4161
4227
  }
4162
4228
  };
4229
+ const handleAvatarUploadComplete = (avatarUrl) => {
4230
+ setSuccess("Avatar updated successfully!");
4231
+ };
4232
+ const handleAvatarUploadError = (error2) => {
4233
+ setError(error2.message || "Failed to upload avatar");
4234
+ };
4163
4235
  const handleRequestEmailChange = async (e) => {
4164
4236
  e.preventDefault();
4165
4237
  setIsLoading(true);
@@ -4262,34 +4334,36 @@ var UserProfile = ({
4262
4334
  }
4263
4335
  )
4264
4336
  ] }),
4265
- showAvatar && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
4266
- /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "avatar", style: {
4337
+ showAvatar && upfilesConfig && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
4338
+ /* @__PURE__ */ jsxRuntime.jsx("label", { style: {
4267
4339
  display: "block",
4268
4340
  marginBottom: "8px",
4269
4341
  fontWeight: 500,
4270
4342
  color: colors.textSecondary,
4271
4343
  fontSize: "14px"
4272
- }, children: "Avatar URL" }),
4273
- /* @__PURE__ */ jsxRuntime.jsx(
4274
- "input",
4344
+ }, children: "Avatar" }),
4345
+ user?.avatar && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginBottom: "12px" }, children: /* @__PURE__ */ jsxRuntime.jsx(
4346
+ "img",
4275
4347
  {
4276
- id: "avatar",
4277
- type: "url",
4278
- value: avatar,
4279
- onChange: (e) => setAvatar(e.target.value),
4280
- disabled: isLoading,
4348
+ src: user.avatar,
4349
+ alt: "Current avatar",
4281
4350
  style: {
4282
- width: "100%",
4283
- padding: "12px 16px",
4284
- border: `1px solid ${colors.borderSecondary}`,
4285
- borderRadius: "8px",
4286
- fontSize: "16px",
4287
- boxSizing: "border-box",
4288
- backgroundColor: colors.bgSecondary,
4289
- color: colors.textPrimary,
4290
- transition: "all 0.2s ease"
4291
- },
4292
- placeholder: "https://example.com/avatar.jpg"
4351
+ width: "80px",
4352
+ height: "80px",
4353
+ borderRadius: "50%",
4354
+ objectFit: "cover",
4355
+ border: `2px solid ${colors.borderSecondary}`
4356
+ }
4357
+ }
4358
+ ) }),
4359
+ /* @__PURE__ */ jsxRuntime.jsx(
4360
+ AvatarUploader,
4361
+ {
4362
+ upfilesConfig,
4363
+ onUploadComplete: handleAvatarUploadComplete,
4364
+ onError: handleAvatarUploadError,
4365
+ maxFileSize: 5 * 1024 * 1024,
4366
+ accept: ["image/*"]
4293
4367
  }
4294
4368
  )
4295
4369
  ] }),
@@ -4401,63 +4475,6 @@ var UserProfile = ({
4401
4475
  ] })
4402
4476
  ] });
4403
4477
  };
4404
- var AvatarUploader = ({
4405
- onUploadComplete,
4406
- onError,
4407
- className,
4408
- buttonClassName,
4409
- dropzoneClassName,
4410
- maxFileSize = 5 * 1024 * 1024,
4411
- // 5MB default
4412
- accept = ["image/*"],
4413
- upfilesConfig
4414
- }) => {
4415
- const { uploadAndUpdateAvatar } = useAuth2();
4416
- const [uploading, setUploading] = React2.useState(false);
4417
- const handleUploadComplete = async (files) => {
4418
- if (files.length === 0)
4419
- return;
4420
- setUploading(true);
4421
- try {
4422
- const file = files[0];
4423
- const response = await uploadAndUpdateAvatar(file.file);
4424
- if (response.success && response.user?.avatar) {
4425
- onUploadComplete?.(response.user.avatar);
4426
- } else {
4427
- throw new Error(response.message || "Failed to update avatar");
4428
- }
4429
- } catch (error) {
4430
- const err = error instanceof Error ? error : new Error("Upload failed");
4431
- onError?.(err);
4432
- } finally {
4433
- setUploading(false);
4434
- }
4435
- };
4436
- const handleError = (error) => {
4437
- onError?.(error);
4438
- };
4439
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className, children: /* @__PURE__ */ jsxRuntime.jsx(
4440
- upfiles.Uploader,
4441
- {
4442
- clientOptions: {
4443
- baseUrl: upfilesConfig.baseUrl,
4444
- apiKey: upfilesConfig.apiKey,
4445
- apiKeyHeader: upfilesConfig.apiKeyHeader || "authorization",
4446
- presignUrl: upfilesConfig.presignUrl,
4447
- presignPath: upfilesConfig.presignPath
4448
- },
4449
- multiple: false,
4450
- accept,
4451
- maxFileSize,
4452
- maxFiles: 1,
4453
- onComplete: handleUploadComplete,
4454
- onError: handleError,
4455
- buttonClassName,
4456
- dropzoneClassName,
4457
- children: uploading ? "Uploading..." : "Upload Avatar"
4458
- }
4459
- ) });
4460
- };
4461
4478
  var AvatarManager = ({
4462
4479
  open,
4463
4480
  onOpenChange,