@thetechfossil/auth2 1.2.15 → 1.2.16

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.
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import React2, { createContext, forwardRef, useContext, useState, useMemo, useEffect, useRef, useCallback } from 'react';
2
+ import React, { createContext, forwardRef, useContext, useState, useMemo, useEffect, useRef, useCallback } from 'react';
3
3
  import axios from 'axios';
4
4
  import { ImageManager, UpfilesClient } from '@thetechfossil/upfiles';
5
5
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
@@ -62,6 +62,11 @@ var HttpClient = class {
62
62
  return Promise.reject(refreshError);
63
63
  }
64
64
  }
65
+ if (error.response && error.response.data && error.response.data.message) {
66
+ const customError = new Error(error.response.data.message);
67
+ customError.response = error.response;
68
+ return Promise.reject(customError);
69
+ }
65
70
  return Promise.reject(error);
66
71
  }
67
72
  );
@@ -643,7 +648,7 @@ var useAuth = (config) => {
643
648
  uploadAndUpdateAvatar
644
649
  };
645
650
  };
646
- var ThemeContext = createContext({ theme: "light", mounted: false });
651
+ var ThemeContext = React.createContext({ theme: "light", mounted: false });
647
652
  function useAuthTheme() {
648
653
  return useContext(ThemeContext);
649
654
  }
@@ -697,7 +702,7 @@ try {
697
702
  } catch (error) {
698
703
  console.warn("react-phone-number-input not available, using fallback");
699
704
  }
700
- var CustomPhoneInput = React2.forwardRef((props, ref) => /* @__PURE__ */ jsx(
705
+ var CustomPhoneInput = React.forwardRef((props, ref) => /* @__PURE__ */ jsx(
701
706
  "input",
702
707
  {
703
708
  ...props,
@@ -3184,7 +3189,19 @@ var UserButton = ({ showName = false, appearance }) => {
3184
3189
  e.currentTarget.style.backgroundColor = "transparent";
3185
3190
  },
3186
3191
  children: [
3187
- /* @__PURE__ */ jsx("div", { style: {
3192
+ user.avatar ? /* @__PURE__ */ jsx(
3193
+ "img",
3194
+ {
3195
+ src: user.avatar,
3196
+ alt: user.name,
3197
+ style: {
3198
+ width: "36px",
3199
+ height: "36px",
3200
+ borderRadius: "50%",
3201
+ objectFit: "cover"
3202
+ }
3203
+ }
3204
+ ) : /* @__PURE__ */ jsx("div", { style: {
3188
3205
  width: "36px",
3189
3206
  height: "36px",
3190
3207
  borderRadius: "50%",
@@ -3221,7 +3238,19 @@ var UserButton = ({ showName = false, appearance }) => {
3221
3238
  alignItems: "center",
3222
3239
  gap: "12px"
3223
3240
  }, children: [
3224
- /* @__PURE__ */ jsx("div", { style: {
3241
+ user.avatar ? /* @__PURE__ */ jsx(
3242
+ "img",
3243
+ {
3244
+ src: user.avatar,
3245
+ alt: user.name,
3246
+ style: {
3247
+ width: "48px",
3248
+ height: "48px",
3249
+ borderRadius: "50%",
3250
+ objectFit: "cover"
3251
+ }
3252
+ }
3253
+ ) : /* @__PURE__ */ jsx("div", { style: {
3225
3254
  width: "48px",
3226
3255
  height: "48px",
3227
3256
  borderRadius: "50%",
@@ -4117,26 +4146,16 @@ var AvatarUploader = ({
4117
4146
  const handleSelect = async (image) => {
4118
4147
  setUploading(true);
4119
4148
  try {
4120
- const proxyUrl = `${upfilesConfig.baseUrl}/api/download?fileKey=${encodeURIComponent(image.key)}`;
4121
- const response = await fetch(proxyUrl, {
4122
- headers: upfilesConfig.apiKey ? {
4123
- [upfilesConfig.apiKeyHeader || "authorization"]: upfilesConfig.apiKey.startsWith("upk_") ? `Bearer ${upfilesConfig.apiKey}` : upfilesConfig.apiKey
4124
- } : {}
4125
- });
4126
- if (!response.ok) {
4127
- throw new Error("Failed to fetch image");
4128
- }
4129
- const blob = await response.blob();
4130
- const file = new File([blob], image.originalName, { type: image.contentType });
4131
- const result = await uploadAndUpdateAvatar(file);
4132
- if (result.success && result.user?.avatar) {
4133
- onUploadComplete?.(result.user.avatar);
4149
+ const { updateProfile } = useAuth2();
4150
+ const response = await updateProfile({ avatar: image.url });
4151
+ if (response.success && response.user?.avatar) {
4152
+ onUploadComplete?.(response.user.avatar);
4134
4153
  setOpen(false);
4135
4154
  } else {
4136
- throw new Error(result.message || "Failed to update avatar");
4155
+ throw new Error(response.message || "Failed to update avatar");
4137
4156
  }
4138
4157
  } catch (error) {
4139
- const err = error instanceof Error ? error : new Error("Upload failed");
4158
+ const err = error instanceof Error ? error : new Error("Failed to update avatar");
4140
4159
  onError?.(err);
4141
4160
  } finally {
4142
4161
  setUploading(false);
@@ -4483,8 +4502,14 @@ var AvatarManager = ({
4483
4502
  gridClassName,
4484
4503
  maxFileSize = 5 * 1024 * 1024,
4485
4504
  // 5MB default
4505
+ maxFiles = 10,
4486
4506
  mode = "full",
4487
4507
  showDelete = false,
4508
+ autoRecordToDb = true,
4509
+ fetchThumbnails = true,
4510
+ projectId,
4511
+ deleteUrl,
4512
+ onDelete,
4488
4513
  upfilesConfig
4489
4514
  }) => {
4490
4515
  const { updateProfile } = useAuth2();
@@ -4516,18 +4541,25 @@ var AvatarManager = ({
4516
4541
  apiKey: upfilesConfig.apiKey,
4517
4542
  apiKeyHeader: upfilesConfig.apiKeyHeader || "authorization",
4518
4543
  presignUrl: upfilesConfig.presignUrl,
4519
- presignPath: upfilesConfig.presignPath
4544
+ presignPath: upfilesConfig.presignPath,
4545
+ headers: upfilesConfig.headers,
4546
+ withCredentials: upfilesConfig.withCredentials
4520
4547
  },
4521
- folderPath: upfilesConfig.folderPath || "avatars/",
4548
+ projectId,
4549
+ folderPath: upfilesConfig.folderPath || "/",
4522
4550
  title,
4523
4551
  description,
4524
4552
  className,
4525
4553
  gridClassName,
4526
4554
  onSelect: handleSelect,
4555
+ onDelete,
4556
+ deleteUrl,
4557
+ autoRecordToDb,
4558
+ fetchThumbnails,
4527
4559
  maxFileSize,
4560
+ maxFiles,
4528
4561
  mode,
4529
- showDelete,
4530
- fetchThumbnails: true
4562
+ showDelete
4531
4563
  }
4532
4564
  );
4533
4565
  };