@thetechfossil/auth2 1.2.6 → 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 +63 -1
- package/dist/index.components.js +209 -30
- package/dist/index.components.js.map +1 -1
- package/dist/index.components.mjs +208 -31
- package/dist/index.components.mjs.map +1 -1
- package/dist/index.d.ts +79 -1
- package/dist/index.js +246 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +226 -32
- package/dist/index.mjs.map +1 -1
- package/dist/index.next.d.ts +70 -1
- package/dist/index.next.js +224 -31
- package/dist/index.next.js.map +1 -1
- package/dist/index.next.mjs +223 -32
- package/dist/index.next.mjs.map +1 -1
- package/dist/index.next.server.js +33 -2
- package/dist/index.next.server.js.map +1 -1
- package/dist/index.next.server.mjs +33 -2
- package/dist/index.next.server.mjs.map +1 -1
- package/dist/index.node.d.ts +16 -1
- package/dist/index.node.js +33 -2
- package/dist/index.node.js.map +1 -1
- package/dist/index.node.mjs +33 -2
- package/dist/index.node.mjs.map +1 -1
- package/package.json +6 -1
- package/dist/index.next.server.d.ts +0 -258
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { UpfilesClient } from '@thetechfossil/upfiles';
|
|
2
|
+
export { ConnectProjectDialog, ImageManager, ProjectFilesWidget, UpfilesClient, Uploader } from '@thetechfossil/upfiles';
|
|
1
3
|
import React, { ReactNode } from 'react';
|
|
2
4
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
5
|
|
|
@@ -64,6 +66,15 @@ interface AuthConfig {
|
|
|
64
66
|
localStorageKey?: string;
|
|
65
67
|
token?: string;
|
|
66
68
|
csrfEnabled?: boolean;
|
|
69
|
+
upfilesConfig?: UpfilesConfig;
|
|
70
|
+
}
|
|
71
|
+
interface UpfilesConfig {
|
|
72
|
+
baseUrl: string;
|
|
73
|
+
apiKey?: string;
|
|
74
|
+
apiKeyHeader?: 'authorization' | 'x-api-key' | 'x-up-api-key';
|
|
75
|
+
presignUrl?: string;
|
|
76
|
+
presignPath?: string;
|
|
77
|
+
folderPath?: string;
|
|
67
78
|
}
|
|
68
79
|
interface Session {
|
|
69
80
|
id: string;
|
|
@@ -109,6 +120,7 @@ interface UseAuthReturn {
|
|
|
109
120
|
refreshCsrfToken: () => Promise<void>;
|
|
110
121
|
changePassword: (oldPassword: string, newPassword: string) => Promise<AuthResponse>;
|
|
111
122
|
updateAvatar: (avatar: string) => Promise<AuthResponse>;
|
|
123
|
+
uploadAndUpdateAvatar: (file: File) => Promise<AuthResponse>;
|
|
112
124
|
requestEmailChange: (newEmail: string) => Promise<AuthResponse>;
|
|
113
125
|
verifyEmailChange: (token: string) => Promise<AuthResponse>;
|
|
114
126
|
generate2FA: () => Promise<MFASetup>;
|
|
@@ -127,6 +139,7 @@ declare class AuthService {
|
|
|
127
139
|
private httpClient;
|
|
128
140
|
private config;
|
|
129
141
|
private token;
|
|
142
|
+
private upfilesClient;
|
|
130
143
|
constructor(config: AuthConfig);
|
|
131
144
|
private loadTokenFromStorage;
|
|
132
145
|
private saveTokenToStorage;
|
|
@@ -152,6 +165,8 @@ declare class AuthService {
|
|
|
152
165
|
resetPassword(token: string, password: string): Promise<AuthResponse>;
|
|
153
166
|
changePassword(oldPassword: string, newPassword: string): Promise<AuthResponse>;
|
|
154
167
|
updateAvatar(avatar: string): Promise<AuthResponse>;
|
|
168
|
+
uploadAndUpdateAvatar(file: File): Promise<AuthResponse>;
|
|
169
|
+
getUpfilesClient(): UpfilesClient | null;
|
|
155
170
|
requestEmailChange(newEmail: string): Promise<AuthResponse>;
|
|
156
171
|
verifyEmailChange(token: string): Promise<AuthResponse>;
|
|
157
172
|
generate2FA(): Promise<{
|
|
@@ -219,6 +234,7 @@ interface AuthContextValue {
|
|
|
219
234
|
resetPassword: (token: string, password: string) => Promise<AuthResponse>;
|
|
220
235
|
changePassword: (oldPassword: string, newPassword: string) => Promise<AuthResponse>;
|
|
221
236
|
updateAvatar: (avatar: string) => Promise<AuthResponse>;
|
|
237
|
+
uploadAndUpdateAvatar: (file: File) => Promise<AuthResponse>;
|
|
222
238
|
requestEmailChange: (newEmail: string) => Promise<AuthResponse>;
|
|
223
239
|
verifyEmailChange: (token: string) => Promise<AuthResponse>;
|
|
224
240
|
generate2FA: () => Promise<any>;
|
|
@@ -398,6 +414,15 @@ interface UserProfileProps {
|
|
|
398
414
|
showAvatar?: boolean;
|
|
399
415
|
showEmailChange?: boolean;
|
|
400
416
|
showPasswordChange?: boolean;
|
|
417
|
+
upfilesConfig?: {
|
|
418
|
+
baseUrl: string;
|
|
419
|
+
apiKey?: string;
|
|
420
|
+
apiKeyHeader?: 'authorization' | 'x-api-key' | 'x-up-api-key';
|
|
421
|
+
presignUrl?: string;
|
|
422
|
+
presignPath?: string;
|
|
423
|
+
folderPath?: string;
|
|
424
|
+
projectId?: string;
|
|
425
|
+
};
|
|
401
426
|
}
|
|
402
427
|
declare const UserProfile: React.FC<UserProfileProps>;
|
|
403
428
|
|
|
@@ -412,6 +437,50 @@ interface PhoneInputProps {
|
|
|
412
437
|
}
|
|
413
438
|
declare const PhoneInput: React.FC<PhoneInputProps>;
|
|
414
439
|
|
|
440
|
+
interface AvatarUploaderProps {
|
|
441
|
+
onUploadComplete?: (avatarUrl: string) => void;
|
|
442
|
+
onError?: (error: Error) => void;
|
|
443
|
+
className?: string;
|
|
444
|
+
buttonClassName?: string;
|
|
445
|
+
dropzoneClassName?: string;
|
|
446
|
+
maxFileSize?: number;
|
|
447
|
+
accept?: string[];
|
|
448
|
+
upfilesConfig: {
|
|
449
|
+
baseUrl: string;
|
|
450
|
+
apiKey?: string;
|
|
451
|
+
apiKeyHeader?: 'authorization' | 'x-api-key' | 'x-up-api-key';
|
|
452
|
+
presignUrl?: string;
|
|
453
|
+
presignPath?: string;
|
|
454
|
+
folderPath?: string;
|
|
455
|
+
projectId?: string;
|
|
456
|
+
};
|
|
457
|
+
buttonText?: string;
|
|
458
|
+
}
|
|
459
|
+
declare const AvatarUploader: React.FC<AvatarUploaderProps>;
|
|
460
|
+
|
|
461
|
+
interface AvatarManagerProps {
|
|
462
|
+
open: boolean;
|
|
463
|
+
onOpenChange: (open: boolean) => void;
|
|
464
|
+
onAvatarUpdated?: (avatarUrl: string) => void;
|
|
465
|
+
onError?: (error: Error) => void;
|
|
466
|
+
title?: string;
|
|
467
|
+
description?: string;
|
|
468
|
+
className?: string;
|
|
469
|
+
gridClassName?: string;
|
|
470
|
+
maxFileSize?: number;
|
|
471
|
+
mode?: 'full' | 'browse' | 'upload';
|
|
472
|
+
showDelete?: boolean;
|
|
473
|
+
upfilesConfig: {
|
|
474
|
+
baseUrl: string;
|
|
475
|
+
apiKey?: string;
|
|
476
|
+
apiKeyHeader?: 'authorization' | 'x-api-key' | 'x-up-api-key';
|
|
477
|
+
presignUrl?: string;
|
|
478
|
+
presignPath?: string;
|
|
479
|
+
folderPath?: string;
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
declare const AvatarManager: React.FC<AvatarManagerProps>;
|
|
483
|
+
|
|
415
484
|
interface UseAuthReturnBase {
|
|
416
485
|
user: User | null;
|
|
417
486
|
isAuthenticated: boolean;
|
|
@@ -425,6 +494,7 @@ interface UseAuthReturnBase {
|
|
|
425
494
|
getProfile: () => Promise<User>;
|
|
426
495
|
getAllUsers: () => Promise<User[]>;
|
|
427
496
|
getUserById: (id: string) => Promise<User>;
|
|
497
|
+
uploadAndUpdateAvatar: (file: File) => Promise<AuthResponse>;
|
|
428
498
|
}
|
|
429
499
|
declare const useAuth: (config: AuthConfig) => UseAuthReturnBase;
|
|
430
500
|
|
|
@@ -441,6 +511,10 @@ declare function useAuthTheme(): ThemeContextType;
|
|
|
441
511
|
declare const index$1_AuthFlow: typeof AuthFlow;
|
|
442
512
|
declare const index$1_AuthProvider: typeof AuthProvider;
|
|
443
513
|
declare const index$1_AuthThemeProvider: typeof AuthThemeProvider;
|
|
514
|
+
declare const index$1_AvatarManager: typeof AvatarManager;
|
|
515
|
+
type index$1_AvatarManagerProps = AvatarManagerProps;
|
|
516
|
+
declare const index$1_AvatarUploader: typeof AvatarUploader;
|
|
517
|
+
type index$1_AvatarUploaderProps = AvatarUploaderProps;
|
|
444
518
|
declare const index$1_ChangePassword: typeof ChangePassword;
|
|
445
519
|
declare const index$1_EmailVerificationPage: typeof EmailVerificationPage;
|
|
446
520
|
declare const index$1_ForgotPassword: typeof ForgotPassword;
|
|
@@ -464,6 +538,10 @@ declare namespace index$1 {
|
|
|
464
538
|
index$1_AuthFlow as AuthFlow,
|
|
465
539
|
index$1_AuthProvider as AuthProvider,
|
|
466
540
|
index$1_AuthThemeProvider as AuthThemeProvider,
|
|
541
|
+
index$1_AvatarManager as AvatarManager,
|
|
542
|
+
index$1_AvatarManagerProps as AvatarManagerProps,
|
|
543
|
+
index$1_AvatarUploader as AvatarUploader,
|
|
544
|
+
index$1_AvatarUploaderProps as AvatarUploaderProps,
|
|
467
545
|
index$1_ChangePassword as ChangePassword,
|
|
468
546
|
index$1_EmailVerificationPage as EmailVerificationPage,
|
|
469
547
|
index$1_ForgotPassword as ForgotPassword,
|
|
@@ -507,4 +585,4 @@ declare namespace index {
|
|
|
507
585
|
};
|
|
508
586
|
}
|
|
509
587
|
|
|
510
|
-
export { AuditLog, AuthConfig, AuthFlow, AuthProvider, AuthResponse, AuthService, ChangePassword, CsrfTokenResponse, EmailVerificationPage, ForgotPassword, HttpClient, LinkedAccount, LoginData, LoginForm, MFASetup, OAuthConfig, OAuthProvider, OtpForm, ProtectedRoute, PublicRoute, RegisterData, RegisterForm, ResetPassword, Session, SignIn, SignOut, SignUp, UpdateUserData, UseAuthReturn, User, UserButton, UserProfile, VerifyData, VerifyEmail, index as node, index$1 as react, useAuth$1 as useAuth };
|
|
588
|
+
export { AuditLog, AuthConfig, AuthFlow, AuthProvider, AuthResponse, AuthService, AvatarManager, AvatarUploader, ChangePassword, CsrfTokenResponse, EmailVerificationPage, ForgotPassword, HttpClient, LinkedAccount, LoginData, LoginForm, MFASetup, OAuthConfig, OAuthProvider, OtpForm, ProtectedRoute, PublicRoute, RegisterData, RegisterForm, ResetPassword, Session, SignIn, SignOut, SignUp, UpdateUserData, UpfilesConfig, UseAuthReturn, User, UserButton, UserProfile, VerifyData, VerifyEmail, index as node, index$1 as react, useAuth$1 as useAuth };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use client";
|
|
2
1
|
'use strict';
|
|
3
2
|
|
|
4
3
|
var axios = require('axios');
|
|
4
|
+
var upfiles = require('@thetechfossil/upfiles');
|
|
5
5
|
var React3 = require('react');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
7
|
var PhoneInputWithCountry = require('react-phone-number-input');
|
|
@@ -124,11 +124,10 @@ var HttpClient = class {
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
};
|
|
127
|
-
|
|
128
|
-
// src/core/auth-service.ts
|
|
129
127
|
var AuthService = class {
|
|
130
128
|
constructor(config) {
|
|
131
129
|
this.token = null;
|
|
130
|
+
this.upfilesClient = null;
|
|
132
131
|
this.config = {
|
|
133
132
|
localStorageKey: "auth_token",
|
|
134
133
|
csrfEnabled: true,
|
|
@@ -136,6 +135,15 @@ var AuthService = class {
|
|
|
136
135
|
};
|
|
137
136
|
this.httpClient = new HttpClient(this.config.baseUrl);
|
|
138
137
|
this.loadTokenFromStorage();
|
|
138
|
+
if (this.config.upfilesConfig) {
|
|
139
|
+
this.upfilesClient = new upfiles.UpfilesClient({
|
|
140
|
+
baseUrl: this.config.upfilesConfig.baseUrl,
|
|
141
|
+
apiKey: this.config.upfilesConfig.apiKey,
|
|
142
|
+
apiKeyHeader: this.config.upfilesConfig.apiKeyHeader,
|
|
143
|
+
presignUrl: this.config.upfilesConfig.presignUrl,
|
|
144
|
+
presignPath: this.config.upfilesConfig.presignPath
|
|
145
|
+
});
|
|
146
|
+
}
|
|
139
147
|
if (typeof window !== "undefined") {
|
|
140
148
|
const frontendBaseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || process.env.NEXT_PUBLIC_APP_URL || window.location.origin;
|
|
141
149
|
if (frontendBaseUrl) {
|
|
@@ -363,6 +371,28 @@ var AuthService = class {
|
|
|
363
371
|
}
|
|
364
372
|
return response;
|
|
365
373
|
}
|
|
374
|
+
async uploadAndUpdateAvatar(file) {
|
|
375
|
+
if (!this.token) {
|
|
376
|
+
throw new Error("Not authenticated");
|
|
377
|
+
}
|
|
378
|
+
if (!this.upfilesClient) {
|
|
379
|
+
throw new Error("Upfiles configuration is required. Please provide upfilesConfig in AuthConfig.");
|
|
380
|
+
}
|
|
381
|
+
try {
|
|
382
|
+
const folderPath = this.config.upfilesConfig?.folderPath || "avatars/";
|
|
383
|
+
const uploadResult = await this.upfilesClient.upload(file, {
|
|
384
|
+
folderPath,
|
|
385
|
+
fetchThumbnails: true
|
|
386
|
+
});
|
|
387
|
+
const response = await this.updateAvatar(uploadResult.publicUrl);
|
|
388
|
+
return response;
|
|
389
|
+
} catch (error) {
|
|
390
|
+
throw new Error(`Failed to upload avatar: ${error.message || "Unknown error"}`);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
getUpfilesClient() {
|
|
394
|
+
return this.upfilesClient;
|
|
395
|
+
}
|
|
366
396
|
async requestEmailChange(newEmail) {
|
|
367
397
|
if (!this.token) {
|
|
368
398
|
throw new Error("Not authenticated");
|
|
@@ -534,7 +564,8 @@ var AuthProvider = ({ children, config }) => {
|
|
|
534
564
|
const authConfig = {
|
|
535
565
|
baseUrl: config?.baseUrl || (typeof window !== "undefined" ? process.env.NEXT_PUBLIC_AUTH_API_URL || process.env.REACT_APP_AUTH_API_URL || "http://localhost:7000" : "http://localhost:7000"),
|
|
536
566
|
localStorageKey: config?.localStorageKey || "auth_token",
|
|
537
|
-
csrfEnabled: config?.csrfEnabled !== void 0 ? config.csrfEnabled : true
|
|
567
|
+
csrfEnabled: config?.csrfEnabled !== void 0 ? config.csrfEnabled : true,
|
|
568
|
+
upfilesConfig: config?.upfilesConfig
|
|
538
569
|
};
|
|
539
570
|
const [authService] = React3.useState(() => new AuthService(authConfig));
|
|
540
571
|
const [user, setUser] = React3.useState(null);
|
|
@@ -684,6 +715,18 @@ var AuthProvider = ({ children, config }) => {
|
|
|
684
715
|
setLoading(false);
|
|
685
716
|
}
|
|
686
717
|
}, [authService]);
|
|
718
|
+
const uploadAndUpdateAvatar = React3.useCallback(async (file) => {
|
|
719
|
+
setLoading(true);
|
|
720
|
+
try {
|
|
721
|
+
const response = await authService.uploadAndUpdateAvatar(file);
|
|
722
|
+
if (response.success && response.user) {
|
|
723
|
+
setUser(response.user);
|
|
724
|
+
}
|
|
725
|
+
return response;
|
|
726
|
+
} finally {
|
|
727
|
+
setLoading(false);
|
|
728
|
+
}
|
|
729
|
+
}, [authService]);
|
|
687
730
|
const requestEmailChange = React3.useCallback(async (newEmail) => {
|
|
688
731
|
setLoading(true);
|
|
689
732
|
try {
|
|
@@ -781,6 +824,7 @@ var AuthProvider = ({ children, config }) => {
|
|
|
781
824
|
resetPassword,
|
|
782
825
|
changePassword,
|
|
783
826
|
updateAvatar,
|
|
827
|
+
uploadAndUpdateAvatar,
|
|
784
828
|
requestEmailChange,
|
|
785
829
|
verifyEmailChange,
|
|
786
830
|
generate2FA,
|
|
@@ -916,6 +960,18 @@ var useAuth2 = (config) => {
|
|
|
916
960
|
setLoading(false);
|
|
917
961
|
}
|
|
918
962
|
}, [authService]);
|
|
963
|
+
const uploadAndUpdateAvatar = React3.useCallback(async (file) => {
|
|
964
|
+
setLoading(true);
|
|
965
|
+
try {
|
|
966
|
+
const response = await authService.uploadAndUpdateAvatar(file);
|
|
967
|
+
if (response.success && response.user) {
|
|
968
|
+
setUser(response.user);
|
|
969
|
+
}
|
|
970
|
+
return response;
|
|
971
|
+
} finally {
|
|
972
|
+
setLoading(false);
|
|
973
|
+
}
|
|
974
|
+
}, [authService]);
|
|
919
975
|
return {
|
|
920
976
|
user,
|
|
921
977
|
isAuthenticated,
|
|
@@ -928,7 +984,8 @@ var useAuth2 = (config) => {
|
|
|
928
984
|
updateProfile,
|
|
929
985
|
getProfile,
|
|
930
986
|
getAllUsers,
|
|
931
|
-
getUserById
|
|
987
|
+
getUserById,
|
|
988
|
+
uploadAndUpdateAvatar
|
|
932
989
|
};
|
|
933
990
|
};
|
|
934
991
|
|
|
@@ -4383,15 +4440,85 @@ var ChangePassword = ({ onSuccess, appearance }) => {
|
|
|
4383
4440
|
)
|
|
4384
4441
|
] }) });
|
|
4385
4442
|
};
|
|
4443
|
+
var AvatarUploader = ({
|
|
4444
|
+
onUploadComplete,
|
|
4445
|
+
onError,
|
|
4446
|
+
className,
|
|
4447
|
+
buttonClassName,
|
|
4448
|
+
maxFileSize = 5 * 1024 * 1024,
|
|
4449
|
+
// 5MB default
|
|
4450
|
+
upfilesConfig,
|
|
4451
|
+
buttonText = "Upload Avatar"
|
|
4452
|
+
}) => {
|
|
4453
|
+
const { uploadAndUpdateAvatar } = useAuth();
|
|
4454
|
+
const [open, setOpen] = React3.useState(false);
|
|
4455
|
+
const [uploading, setUploading] = React3.useState(false);
|
|
4456
|
+
const handleSelect = async (image) => {
|
|
4457
|
+
setUploading(true);
|
|
4458
|
+
try {
|
|
4459
|
+
const response = await fetch(image.url);
|
|
4460
|
+
const blob = await response.blob();
|
|
4461
|
+
const file = new File([blob], image.originalName, { type: image.contentType });
|
|
4462
|
+
const result = await uploadAndUpdateAvatar(file);
|
|
4463
|
+
if (result.success && result.user?.avatar) {
|
|
4464
|
+
onUploadComplete?.(result.user.avatar);
|
|
4465
|
+
setOpen(false);
|
|
4466
|
+
} else {
|
|
4467
|
+
throw new Error(result.message || "Failed to update avatar");
|
|
4468
|
+
}
|
|
4469
|
+
} catch (error) {
|
|
4470
|
+
const err = error instanceof Error ? error : new Error("Upload failed");
|
|
4471
|
+
onError?.(err);
|
|
4472
|
+
} finally {
|
|
4473
|
+
setUploading(false);
|
|
4474
|
+
}
|
|
4475
|
+
};
|
|
4476
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, children: [
|
|
4477
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4478
|
+
"button",
|
|
4479
|
+
{
|
|
4480
|
+
type: "button",
|
|
4481
|
+
onClick: () => setOpen(true),
|
|
4482
|
+
disabled: uploading,
|
|
4483
|
+
className: buttonClassName || "px-4 py-2 text-sm rounded border bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50",
|
|
4484
|
+
children: uploading ? "Uploading..." : buttonText
|
|
4485
|
+
}
|
|
4486
|
+
),
|
|
4487
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4488
|
+
upfiles.ImageManager,
|
|
4489
|
+
{
|
|
4490
|
+
open,
|
|
4491
|
+
onOpenChange: setOpen,
|
|
4492
|
+
clientOptions: {
|
|
4493
|
+
baseUrl: upfilesConfig.baseUrl,
|
|
4494
|
+
apiKey: upfilesConfig.apiKey,
|
|
4495
|
+
apiKeyHeader: upfilesConfig.apiKeyHeader || "authorization",
|
|
4496
|
+
presignUrl: upfilesConfig.presignUrl,
|
|
4497
|
+
presignPath: upfilesConfig.presignPath
|
|
4498
|
+
},
|
|
4499
|
+
projectId: upfilesConfig.projectId,
|
|
4500
|
+
folderPath: upfilesConfig.folderPath || "avatars/",
|
|
4501
|
+
title: "Select Avatar",
|
|
4502
|
+
description: "Upload a new avatar or select from existing images.",
|
|
4503
|
+
mode: "full",
|
|
4504
|
+
maxFileSize,
|
|
4505
|
+
maxFiles: 1,
|
|
4506
|
+
autoRecordToDb: true,
|
|
4507
|
+
fetchThumbnails: true,
|
|
4508
|
+
onSelect: handleSelect
|
|
4509
|
+
}
|
|
4510
|
+
)
|
|
4511
|
+
] });
|
|
4512
|
+
};
|
|
4386
4513
|
var UserProfile = ({
|
|
4387
4514
|
showAvatar = true,
|
|
4388
4515
|
showEmailChange = true,
|
|
4389
|
-
showPasswordChange = true
|
|
4516
|
+
showPasswordChange = true,
|
|
4517
|
+
upfilesConfig
|
|
4390
4518
|
}) => {
|
|
4391
4519
|
const { user, updateProfile, requestEmailChange } = useAuth();
|
|
4392
4520
|
const colors = useThemeColors();
|
|
4393
4521
|
const [name, setName] = React3.useState(user?.name || "");
|
|
4394
|
-
const [avatar, setAvatar] = React3.useState(user?.avatar || "");
|
|
4395
4522
|
const [phoneNumber, setPhoneNumber] = React3.useState(user?.phoneNumber || "");
|
|
4396
4523
|
const [newEmail, setNewEmail] = React3.useState("");
|
|
4397
4524
|
const [isLoading, setIsLoading] = React3.useState(false);
|
|
@@ -4407,9 +4534,6 @@ var UserProfile = ({
|
|
|
4407
4534
|
if (name !== user?.name) {
|
|
4408
4535
|
updates.name = name;
|
|
4409
4536
|
}
|
|
4410
|
-
if (showAvatar && avatar !== user?.avatar) {
|
|
4411
|
-
updates.avatar = avatar;
|
|
4412
|
-
}
|
|
4413
4537
|
if (phoneNumber !== user?.phoneNumber) {
|
|
4414
4538
|
updates.phoneNumber = phoneNumber;
|
|
4415
4539
|
}
|
|
@@ -4430,6 +4554,12 @@ var UserProfile = ({
|
|
|
4430
4554
|
setIsLoading(false);
|
|
4431
4555
|
}
|
|
4432
4556
|
};
|
|
4557
|
+
const handleAvatarUploadComplete = (avatarUrl) => {
|
|
4558
|
+
setSuccess("Avatar updated successfully!");
|
|
4559
|
+
};
|
|
4560
|
+
const handleAvatarUploadError = (error2) => {
|
|
4561
|
+
setError(error2.message || "Failed to upload avatar");
|
|
4562
|
+
};
|
|
4433
4563
|
const handleRequestEmailChange = async (e) => {
|
|
4434
4564
|
e.preventDefault();
|
|
4435
4565
|
setIsLoading(true);
|
|
@@ -4532,34 +4662,36 @@ var UserProfile = ({
|
|
|
4532
4662
|
}
|
|
4533
4663
|
)
|
|
4534
4664
|
] }),
|
|
4535
|
-
showAvatar && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
|
|
4536
|
-
/* @__PURE__ */ jsxRuntime.jsx("label", {
|
|
4665
|
+
showAvatar && upfilesConfig && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
|
|
4666
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { style: {
|
|
4537
4667
|
display: "block",
|
|
4538
4668
|
marginBottom: "8px",
|
|
4539
4669
|
fontWeight: 500,
|
|
4540
4670
|
color: colors.textSecondary,
|
|
4541
4671
|
fontSize: "14px"
|
|
4542
|
-
}, children: "Avatar
|
|
4543
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4544
|
-
"
|
|
4672
|
+
}, children: "Avatar" }),
|
|
4673
|
+
user?.avatar && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginBottom: "12px" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4674
|
+
"img",
|
|
4545
4675
|
{
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
value: avatar,
|
|
4549
|
-
onChange: (e) => setAvatar(e.target.value),
|
|
4550
|
-
disabled: isLoading,
|
|
4676
|
+
src: user.avatar,
|
|
4677
|
+
alt: "Current avatar",
|
|
4551
4678
|
style: {
|
|
4552
|
-
width: "
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
4679
|
+
width: "80px",
|
|
4680
|
+
height: "80px",
|
|
4681
|
+
borderRadius: "50%",
|
|
4682
|
+
objectFit: "cover",
|
|
4683
|
+
border: `2px solid ${colors.borderSecondary}`
|
|
4684
|
+
}
|
|
4685
|
+
}
|
|
4686
|
+
) }),
|
|
4687
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4688
|
+
AvatarUploader,
|
|
4689
|
+
{
|
|
4690
|
+
upfilesConfig,
|
|
4691
|
+
onUploadComplete: handleAvatarUploadComplete,
|
|
4692
|
+
onError: handleAvatarUploadError,
|
|
4693
|
+
maxFileSize: 5 * 1024 * 1024,
|
|
4694
|
+
accept: ["image/*"]
|
|
4563
4695
|
}
|
|
4564
4696
|
)
|
|
4565
4697
|
] }),
|
|
@@ -4671,6 +4803,65 @@ var UserProfile = ({
|
|
|
4671
4803
|
] })
|
|
4672
4804
|
] });
|
|
4673
4805
|
};
|
|
4806
|
+
var AvatarManager = ({
|
|
4807
|
+
open,
|
|
4808
|
+
onOpenChange,
|
|
4809
|
+
onAvatarUpdated,
|
|
4810
|
+
onError,
|
|
4811
|
+
title = "Select Avatar",
|
|
4812
|
+
description = "Choose an existing image or upload a new one",
|
|
4813
|
+
className,
|
|
4814
|
+
gridClassName,
|
|
4815
|
+
maxFileSize = 5 * 1024 * 1024,
|
|
4816
|
+
// 5MB default
|
|
4817
|
+
mode = "full",
|
|
4818
|
+
showDelete = false,
|
|
4819
|
+
upfilesConfig
|
|
4820
|
+
}) => {
|
|
4821
|
+
const { updateProfile } = useAuth();
|
|
4822
|
+
const [updating, setUpdating] = React3.useState(false);
|
|
4823
|
+
const handleSelect = async (image) => {
|
|
4824
|
+
setUpdating(true);
|
|
4825
|
+
try {
|
|
4826
|
+
const response = await updateProfile({ avatar: image.url });
|
|
4827
|
+
if (response.success && response.user?.avatar) {
|
|
4828
|
+
onAvatarUpdated?.(response.user.avatar);
|
|
4829
|
+
onOpenChange(false);
|
|
4830
|
+
} else {
|
|
4831
|
+
throw new Error(response.message || "Failed to update avatar");
|
|
4832
|
+
}
|
|
4833
|
+
} catch (error) {
|
|
4834
|
+
const err = error instanceof Error ? error : new Error("Failed to update avatar");
|
|
4835
|
+
onError?.(err);
|
|
4836
|
+
} finally {
|
|
4837
|
+
setUpdating(false);
|
|
4838
|
+
}
|
|
4839
|
+
};
|
|
4840
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4841
|
+
upfiles.ImageManager,
|
|
4842
|
+
{
|
|
4843
|
+
open,
|
|
4844
|
+
onOpenChange,
|
|
4845
|
+
clientOptions: {
|
|
4846
|
+
baseUrl: upfilesConfig.baseUrl,
|
|
4847
|
+
apiKey: upfilesConfig.apiKey,
|
|
4848
|
+
apiKeyHeader: upfilesConfig.apiKeyHeader || "authorization",
|
|
4849
|
+
presignUrl: upfilesConfig.presignUrl,
|
|
4850
|
+
presignPath: upfilesConfig.presignPath
|
|
4851
|
+
},
|
|
4852
|
+
folderPath: upfilesConfig.folderPath || "avatars/",
|
|
4853
|
+
title,
|
|
4854
|
+
description,
|
|
4855
|
+
className,
|
|
4856
|
+
gridClassName,
|
|
4857
|
+
onSelect: handleSelect,
|
|
4858
|
+
maxFileSize,
|
|
4859
|
+
mode,
|
|
4860
|
+
showDelete,
|
|
4861
|
+
fetchThumbnails: true
|
|
4862
|
+
}
|
|
4863
|
+
);
|
|
4864
|
+
};
|
|
4674
4865
|
|
|
4675
4866
|
// src/react/index.ts
|
|
4676
4867
|
var react_exports = {};
|
|
@@ -4678,6 +4869,8 @@ __export(react_exports, {
|
|
|
4678
4869
|
AuthFlow: () => AuthFlow,
|
|
4679
4870
|
AuthProvider: () => AuthProvider,
|
|
4680
4871
|
AuthThemeProvider: () => AuthThemeProvider,
|
|
4872
|
+
AvatarManager: () => AvatarManager,
|
|
4873
|
+
AvatarUploader: () => AvatarUploader,
|
|
4681
4874
|
ChangePassword: () => ChangePassword,
|
|
4682
4875
|
EmailVerificationPage: () => EmailVerificationPage,
|
|
4683
4876
|
ForgotPassword: () => ForgotPassword,
|
|
@@ -4783,9 +4976,31 @@ var AuthClient = class extends AuthService {
|
|
|
4783
4976
|
}
|
|
4784
4977
|
};
|
|
4785
4978
|
|
|
4979
|
+
Object.defineProperty(exports, 'ConnectProjectDialog', {
|
|
4980
|
+
enumerable: true,
|
|
4981
|
+
get: function () { return upfiles.ConnectProjectDialog; }
|
|
4982
|
+
});
|
|
4983
|
+
Object.defineProperty(exports, 'ImageManager', {
|
|
4984
|
+
enumerable: true,
|
|
4985
|
+
get: function () { return upfiles.ImageManager; }
|
|
4986
|
+
});
|
|
4987
|
+
Object.defineProperty(exports, 'ProjectFilesWidget', {
|
|
4988
|
+
enumerable: true,
|
|
4989
|
+
get: function () { return upfiles.ProjectFilesWidget; }
|
|
4990
|
+
});
|
|
4991
|
+
Object.defineProperty(exports, 'UpfilesClient', {
|
|
4992
|
+
enumerable: true,
|
|
4993
|
+
get: function () { return upfiles.UpfilesClient; }
|
|
4994
|
+
});
|
|
4995
|
+
Object.defineProperty(exports, 'Uploader', {
|
|
4996
|
+
enumerable: true,
|
|
4997
|
+
get: function () { return upfiles.Uploader; }
|
|
4998
|
+
});
|
|
4786
4999
|
exports.AuthFlow = AuthFlow;
|
|
4787
5000
|
exports.AuthProvider = AuthProvider;
|
|
4788
5001
|
exports.AuthService = AuthService;
|
|
5002
|
+
exports.AvatarManager = AvatarManager;
|
|
5003
|
+
exports.AvatarUploader = AvatarUploader;
|
|
4789
5004
|
exports.ChangePassword = ChangePassword;
|
|
4790
5005
|
exports.EmailVerificationPage = EmailVerificationPage;
|
|
4791
5006
|
exports.ForgotPassword = ForgotPassword;
|