@djangocfg/api 2.1.96 → 2.1.99

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.96",
3
+ "version": "2.1.99",
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,19 +74,19 @@
74
74
  "check": "tsc --noEmit"
75
75
  },
76
76
  "peerDependencies": {
77
- "@djangocfg/ui-nextjs": "^2.1.96",
77
+ "@djangocfg/ui-nextjs": "^2.1.99",
78
78
  "consola": "^3.4.2",
79
- "next": "^14 || ^15",
79
+ "next": ">=16.0.0",
80
80
  "p-retry": "^7.0.0",
81
- "react": "^18 || ^19",
81
+ "react": "^19.0.0",
82
82
  "swr": "^2.3.7",
83
83
  "zod": "^4.1.13"
84
84
  },
85
85
  "devDependencies": {
86
86
  "@types/node": "^24.7.2",
87
87
  "@types/react": "^19.0.0",
88
- "@djangocfg/typescript-config": "^2.1.96",
89
- "next": "^15.0.0",
88
+ "@djangocfg/typescript-config": "^2.1.99",
89
+ "next": "^16.0.0",
90
90
  "react": "^19.0.0",
91
91
  "tsup": "^8.5.0",
92
92
  "typescript": "^5.9.3"
@@ -615,11 +615,72 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children, config })
615
615
  );
616
616
  };
617
617
 
618
+ /**
619
+ * Default auth state for SSR/outside provider
620
+ * Returns safe defaults that indicate "not authenticated, not loading"
621
+ */
622
+ const defaultAuthState: AuthContextType = {
623
+ user: null,
624
+ isLoading: false,
625
+ isAuthenticated: false,
626
+ isAdminUser: false,
627
+ loadCurrentProfile: async () => {
628
+ authLogger.warn('useAuth: loadCurrentProfile called outside AuthProvider');
629
+ },
630
+ checkAuthAndRedirect: async () => {
631
+ authLogger.warn('useAuth: checkAuthAndRedirect called outside AuthProvider');
632
+ },
633
+ getToken: () => null,
634
+ getRefreshToken: () => null,
635
+ getSavedEmail: () => null,
636
+ saveEmail: () => {
637
+ authLogger.warn('useAuth: saveEmail called outside AuthProvider');
638
+ },
639
+ clearSavedEmail: () => {},
640
+ getSavedPhone: () => null,
641
+ savePhone: () => {
642
+ authLogger.warn('useAuth: savePhone called outside AuthProvider');
643
+ },
644
+ clearSavedPhone: () => {},
645
+ requestOTP: async () => {
646
+ authLogger.warn('useAuth: requestOTP called outside AuthProvider');
647
+ return { success: false, message: 'AuthProvider not available' };
648
+ },
649
+ verifyOTP: async () => {
650
+ authLogger.warn('useAuth: verifyOTP called outside AuthProvider');
651
+ return { success: false, message: 'AuthProvider not available' };
652
+ },
653
+ refreshToken: async () => {
654
+ authLogger.warn('useAuth: refreshToken called outside AuthProvider');
655
+ return { success: false, message: 'AuthProvider not available' };
656
+ },
657
+ logout: async () => {
658
+ authLogger.warn('useAuth: logout called outside AuthProvider');
659
+ },
660
+ saveRedirectUrl: () => {},
661
+ getRedirectUrl: () => null,
662
+ clearRedirectUrl: () => {},
663
+ hasRedirectUrl: () => false,
664
+ };
665
+
666
+ /**
667
+ * Hook to access auth context
668
+ *
669
+ * SSR-safe: Returns default unauthenticated state when called outside AuthProvider
670
+ * (e.g., during static page generation or server-side rendering)
671
+ */
618
672
  export const useAuth = (): AuthContextType => {
619
673
  const context = useContext(AuthContext);
674
+
620
675
  if (context === undefined) {
621
- throw new Error('useAuth must be used within an AuthProvider');
676
+ // SSR or outside provider - return safe defaults
677
+ // Log only in development to help debugging
678
+ if (typeof window !== 'undefined' && process.env.NODE_ENV === 'development') {
679
+ authLogger.debug('useAuth called outside AuthProvider, returning default state');
680
+ }
681
+ return defaultAuthState;
622
682
  }
683
+
623
684
  return context;
624
685
  };
625
686