@djangocfg/api 2.1.100 → 2.1.102

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@djangocfg/api",
3
- "version": "2.1.100",
3
+ "version": "2.1.102",
4
4
  "description": "Auto-generated TypeScript API client with React hooks, SWR integration, and Zod validation for Django REST Framework backends",
5
5
  "keywords": [
6
6
  "django",
@@ -74,7 +74,7 @@
74
74
  "check": "tsc --noEmit"
75
75
  },
76
76
  "peerDependencies": {
77
- "@djangocfg/ui-nextjs": "^2.1.100",
77
+ "@djangocfg/ui-nextjs": "^2.1.102",
78
78
  "consola": "^3.4.2",
79
79
  "next": ">=16.0.0",
80
80
  "p-retry": "^7.0.0",
@@ -85,7 +85,7 @@
85
85
  "devDependencies": {
86
86
  "@types/node": "^24.7.2",
87
87
  "@types/react": "^19.0.0",
88
- "@djangocfg/typescript-config": "^2.1.100",
88
+ "@djangocfg/typescript-config": "^2.1.102",
89
89
  "next": "^16.0.0",
90
90
  "react": "^19.0.0",
91
91
  "tsup": "^8.5.0",
@@ -510,7 +510,7 @@ const AuthProviderInternal: React.FC<AuthProviderProps> = ({ children, config })
510
510
  }
511
511
  }, [clearAuthState, accounts]);
512
512
 
513
- const logout = useCallback(async (): Promise<void> => {
513
+ const logout = useCallback(async (options?: { skipConfirm?: boolean }): Promise<void> => {
514
514
  const performLogout = () => {
515
515
  // Track logout
516
516
  Analytics.event(AnalyticsEvent.AUTH_LOGOUT, {
@@ -527,6 +527,12 @@ const AuthProviderInternal: React.FC<AuthProviderProps> = ({ children, config })
527
527
  router.hardReplace(authCallbackUrl);
528
528
  };
529
529
 
530
+ // Skip confirmation if requested (e.g., after account deletion)
531
+ if (options?.skipConfirm) {
532
+ performLogout();
533
+ return;
534
+ }
535
+
530
536
  // Use config.onConfirm if provided, otherwise use a simple confirm
531
537
  if (configRef.current?.onConfirm) {
532
538
  const { confirmed } = await configRef.current.onConfirm({
@@ -553,6 +559,24 @@ const AuthProviderInternal: React.FC<AuthProviderProps> = ({ children, config })
553
559
  return Boolean(user?.is_staff || user?.is_superuser);
554
560
  }, [user]);
555
561
 
562
+ // Profile management: Update profile data
563
+ const updateProfile = useCallback(
564
+ async (data: { first_name?: string; last_name?: string; username?: string }): Promise<UserProfile> => {
565
+ const result = await accounts.partialUpdateProfile(data);
566
+ return result as UserProfile;
567
+ },
568
+ [accounts]
569
+ );
570
+
571
+ // Profile management: Upload avatar
572
+ const uploadAvatar = useCallback(
573
+ async (avatar: File | Blob): Promise<UserProfile> => {
574
+ const result = await accounts.uploadAvatar(avatar);
575
+ return result as UserProfile;
576
+ },
577
+ [accounts]
578
+ );
579
+
556
580
  // Memoized context value
557
581
  const value = useMemo<AuthContextType>(
558
582
  () => ({
@@ -580,6 +604,9 @@ const AuthProviderInternal: React.FC<AuthProviderProps> = ({ children, config })
580
604
  getRedirectUrl: redirectManager.getFinalRedirectUrl,
581
605
  clearRedirectUrl: redirectManager.clearRedirect,
582
606
  hasRedirectUrl: redirectManager.hasRedirect,
607
+ // Profile management
608
+ updateProfile,
609
+ uploadAvatar,
583
610
  }),
584
611
  [
585
612
  user,
@@ -598,6 +625,8 @@ const AuthProviderInternal: React.FC<AuthProviderProps> = ({ children, config })
598
625
  refreshToken,
599
626
  logout,
600
627
  redirectManager,
628
+ updateProfile,
629
+ uploadAvatar,
601
630
  ],
602
631
  );
603
632
 
@@ -654,13 +683,21 @@ const defaultAuthState: AuthContextType = {
654
683
  authLogger.warn('useAuth: refreshToken called outside AuthProvider');
655
684
  return { success: false, message: 'AuthProvider not available' };
656
685
  },
657
- logout: async () => {
686
+ logout: async (_options?: { skipConfirm?: boolean }) => {
658
687
  authLogger.warn('useAuth: logout called outside AuthProvider');
659
688
  },
660
689
  saveRedirectUrl: () => {},
661
690
  getRedirectUrl: () => null,
662
691
  clearRedirectUrl: () => {},
663
692
  hasRedirectUrl: () => false,
693
+ updateProfile: async () => {
694
+ authLogger.warn('useAuth: updateProfile called outside AuthProvider');
695
+ return {} as UserProfile;
696
+ },
697
+ uploadAvatar: async () => {
698
+ authLogger.warn('useAuth: uploadAvatar called outside AuthProvider');
699
+ return {} as UserProfile;
700
+ },
664
701
  };
665
702
 
666
703
  /**
@@ -57,13 +57,17 @@ export interface AuthContextType {
57
57
  should_prompt_2fa?: boolean;
58
58
  }>;
59
59
  refreshToken: () => Promise<{ success: boolean; message: string }>;
60
- logout: () => Promise<void>;
60
+ logout: (options?: { skipConfirm?: boolean }) => Promise<void>;
61
61
 
62
62
  // Redirect URL Methods - for saving URL before auth redirect
63
63
  saveRedirectUrl: (url: string) => void;
64
64
  getRedirectUrl: () => string;
65
65
  clearRedirectUrl: () => void;
66
66
  hasRedirectUrl: () => boolean;
67
+
68
+ // Profile Management Methods
69
+ updateProfile: (data: { first_name?: string; last_name?: string; username?: string }) => Promise<UserProfile>;
70
+ uploadAvatar: (avatar: File | Blob) => Promise<UserProfile>;
67
71
  }
68
72
 
69
73
  // Provider props