@djangocfg/api 2.1.129 → 2.1.130
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/auth.cjs +17 -19
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +4 -1
- package/dist/auth.d.ts +4 -1
- package/dist/auth.mjs +17 -19
- package/dist/auth.mjs.map +1 -1
- package/package.json +2 -2
- package/src/auth/context/AccountsContext.tsx +23 -28
- package/src/auth/context/AuthContext.tsx +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@djangocfg/api",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.130",
|
|
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",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"@types/node": "^24.7.2",
|
|
86
86
|
"@types/react": "^19.0.0",
|
|
87
|
-
"@djangocfg/typescript-config": "^2.1.
|
|
87
|
+
"@djangocfg/typescript-config": "^2.1.130",
|
|
88
88
|
"next": "^16.0.0",
|
|
89
89
|
"react": "^19.0.0",
|
|
90
90
|
"tsup": "^8.5.0",
|
|
@@ -60,7 +60,7 @@ export interface AccountsContextValue {
|
|
|
60
60
|
updateProfile: (data: UserProfileUpdateRequest) => Promise<User>;
|
|
61
61
|
partialUpdateProfile: (data: PatchedUserProfileUpdateRequest) => Promise<User>;
|
|
62
62
|
uploadAvatar: (avatar: File | Blob) => Promise<User>;
|
|
63
|
-
refreshProfile: (callerId?: string) => Promise<User | undefined>;
|
|
63
|
+
refreshProfile: (options?: { callerId?: string; force?: boolean }) => Promise<User | undefined>;
|
|
64
64
|
|
|
65
65
|
// Authentication
|
|
66
66
|
requestOTP: (data: OTPRequestRequest) => Promise<OTPRequestResponse>;
|
|
@@ -114,30 +114,25 @@ export function AccountsProvider({ children }: AccountsProviderProps) {
|
|
|
114
114
|
const otpVerifyMutation = useCreateAccountsOtpVerifyCreate();
|
|
115
115
|
const tokenRefreshMutation = useCreateAccountsTokenRefreshCreate();
|
|
116
116
|
|
|
117
|
-
// Refresh profile - fetch
|
|
118
|
-
const refreshProfile = useCallback(async (callerId?: string): Promise<User | undefined> => {
|
|
119
|
-
|
|
120
|
-
const currentProfile = profileRef.current;
|
|
117
|
+
// Refresh profile - fetch from API and update cache
|
|
118
|
+
const refreshProfile = useCallback(async (options?: { callerId?: string; force?: boolean }): Promise<User | undefined> => {
|
|
119
|
+
const { callerId, force } = options || {};
|
|
121
120
|
const currentLoading = isLoadingRef.current;
|
|
122
121
|
|
|
123
|
-
// Prevent duplicate calls
|
|
124
|
-
if (
|
|
125
|
-
authLogger.debug(`Profile
|
|
126
|
-
return
|
|
122
|
+
// Prevent duplicate concurrent calls
|
|
123
|
+
if (currentLoading) {
|
|
124
|
+
authLogger.debug(`Profile loading in progress, skipping (caller: ${callerId})`);
|
|
125
|
+
return profileRef.current;
|
|
127
126
|
}
|
|
128
127
|
|
|
129
128
|
setIsLoadingProfile(true);
|
|
130
129
|
isLoadingRef.current = true;
|
|
131
130
|
setProfileError(null);
|
|
132
131
|
try {
|
|
133
|
-
|
|
134
|
-
if (callerId) {
|
|
135
|
-
authLogger.debug(`Profile refresh called by: ${callerId}`);
|
|
136
|
-
}
|
|
132
|
+
authLogger.debug(`Fetching profile from API (caller: ${callerId}, force: ${force})`);
|
|
137
133
|
const result = await getAccountsProfileRetrieve(apiAccounts);
|
|
138
134
|
setProfile(result);
|
|
139
135
|
profileRef.current = result;
|
|
140
|
-
// Save to cache with 1 hour TTL
|
|
141
136
|
setCachedProfile(result);
|
|
142
137
|
return result;
|
|
143
138
|
} catch (error) {
|
|
@@ -148,27 +143,27 @@ export function AccountsProvider({ children }: AccountsProviderProps) {
|
|
|
148
143
|
setIsLoadingProfile(false);
|
|
149
144
|
isLoadingRef.current = false;
|
|
150
145
|
}
|
|
151
|
-
}, []);
|
|
146
|
+
}, []);
|
|
152
147
|
|
|
153
|
-
// Update profile (full)
|
|
148
|
+
// Update profile (full) - then reload from API
|
|
154
149
|
const updateProfile = async (data: UserProfileUpdateRequest): Promise<User> => {
|
|
155
|
-
|
|
156
|
-
await refreshProfile('
|
|
157
|
-
return
|
|
150
|
+
await updateMutation(data, apiAccounts);
|
|
151
|
+
const user = await refreshProfile({ callerId: 'updateProfile', force: true });
|
|
152
|
+
return user as User;
|
|
158
153
|
};
|
|
159
154
|
|
|
160
|
-
// Partial update profile
|
|
155
|
+
// Partial update profile - then reload from API
|
|
161
156
|
const partialUpdateProfile = async (data: PatchedUserProfileUpdateRequest): Promise<User> => {
|
|
162
|
-
|
|
163
|
-
await refreshProfile('
|
|
164
|
-
return
|
|
157
|
+
await partialUpdateMutation(data, apiAccounts);
|
|
158
|
+
const user = await refreshProfile({ callerId: 'partialUpdateProfile', force: true });
|
|
159
|
+
return user as User;
|
|
165
160
|
};
|
|
166
161
|
|
|
167
|
-
// Upload avatar
|
|
162
|
+
// Upload avatar - then reload from API
|
|
168
163
|
const uploadAvatar = async (avatar: File | Blob): Promise<User> => {
|
|
169
|
-
|
|
170
|
-
await refreshProfile('
|
|
171
|
-
return
|
|
164
|
+
await avatarMutation({ avatar }, apiAccounts);
|
|
165
|
+
const user = await refreshProfile({ callerId: 'uploadAvatar', force: true });
|
|
166
|
+
return user as User;
|
|
172
167
|
};
|
|
173
168
|
|
|
174
169
|
// Request OTP
|
|
@@ -192,7 +187,7 @@ export function AccountsProvider({ children }: AccountsProviderProps) {
|
|
|
192
187
|
if (result.access && result.refresh) {
|
|
193
188
|
apiAccounts.setToken(result.access, result.refresh);
|
|
194
189
|
// Refresh profile to load user data with new token
|
|
195
|
-
await refreshProfile('
|
|
190
|
+
await refreshProfile({ callerId: 'verifyOTP', force: true });
|
|
196
191
|
}
|
|
197
192
|
|
|
198
193
|
return result as OTPVerifyResponse;
|
|
@@ -163,8 +163,8 @@ const AuthProviderInternal: React.FC<AuthProviderProps> = ({ children, config })
|
|
|
163
163
|
return;
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
// Refresh profile from AccountsContext
|
|
167
|
-
const refreshedProfile = await accounts.refreshProfile(finalCallerId);
|
|
166
|
+
// Refresh profile from AccountsContext
|
|
167
|
+
const refreshedProfile = await accounts.refreshProfile({ callerId: finalCallerId });
|
|
168
168
|
|
|
169
169
|
if (refreshedProfile) {
|
|
170
170
|
authLogger.info('Profile loaded successfully:', refreshedProfile.id);
|