@djangocfg/api 2.1.51 → 2.1.53
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 +25 -4
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.mjs +25 -4
- package/dist/auth.mjs.map +1 -1
- package/package.json +3 -3
- package/src/auth/hooks/useAuthRedirect.ts +40 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@djangocfg/api",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.53",
|
|
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.
|
|
77
|
+
"@djangocfg/ui-nextjs": "^2.1.53",
|
|
78
78
|
"consola": "^3.4.2",
|
|
79
79
|
"next": "^14 || ^15",
|
|
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.
|
|
88
|
+
"@djangocfg/typescript-config": "^2.1.53",
|
|
89
89
|
"next": "^15.0.0",
|
|
90
90
|
"react": "^19.0.0",
|
|
91
91
|
"tsup": "^8.5.0",
|
|
@@ -7,6 +7,33 @@ export interface AuthRedirectOptions {
|
|
|
7
7
|
clearOnUse?: boolean;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Read redirect URL directly from sessionStorage (bypasses React state)
|
|
12
|
+
* This is needed because different component instances have different React states
|
|
13
|
+
*/
|
|
14
|
+
const getRedirectFromStorage = (): string => {
|
|
15
|
+
if (typeof window === 'undefined') return '';
|
|
16
|
+
try {
|
|
17
|
+
const item = window.sessionStorage.getItem(AUTH_REDIRECT_KEY);
|
|
18
|
+
return item ? JSON.parse(item) : '';
|
|
19
|
+
} catch {
|
|
20
|
+
return '';
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Clear redirect URL directly from sessionStorage
|
|
26
|
+
*/
|
|
27
|
+
const clearRedirectFromStorage = (): void => {
|
|
28
|
+
if (typeof window === 'undefined') return;
|
|
29
|
+
try {
|
|
30
|
+
window.sessionStorage.removeItem(AUTH_REDIRECT_KEY);
|
|
31
|
+
window.sessionStorage.removeItem(`${AUTH_REDIRECT_KEY}_timestamp`);
|
|
32
|
+
} catch {
|
|
33
|
+
// Ignore errors
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
10
37
|
export const useAuthRedirectManager = (options: AuthRedirectOptions = {}) => {
|
|
11
38
|
const { fallbackUrl = '/dashboard', clearOnUse = true } = options;
|
|
12
39
|
const [redirectUrl, setRedirectUrl, removeRedirectUrl] = useSessionStorage<string>(AUTH_REDIRECT_KEY, '');
|
|
@@ -16,23 +43,32 @@ export const useAuthRedirectManager = (options: AuthRedirectOptions = {}) => {
|
|
|
16
43
|
};
|
|
17
44
|
|
|
18
45
|
const getRedirect = () => {
|
|
19
|
-
|
|
46
|
+
// Read directly from storage to get latest value across components
|
|
47
|
+
return getRedirectFromStorage() || redirectUrl;
|
|
20
48
|
};
|
|
21
49
|
|
|
22
50
|
const clearRedirect = () => {
|
|
23
51
|
removeRedirectUrl();
|
|
52
|
+
clearRedirectFromStorage();
|
|
24
53
|
};
|
|
25
54
|
|
|
26
55
|
const hasRedirect = () => {
|
|
27
|
-
|
|
56
|
+
const stored = getRedirectFromStorage();
|
|
57
|
+
return stored.length > 0 || redirectUrl.length > 0;
|
|
28
58
|
};
|
|
29
59
|
|
|
30
60
|
const getFinalRedirectUrl = () => {
|
|
31
|
-
|
|
61
|
+
// Read directly from storage to get latest value across components
|
|
62
|
+
const stored = getRedirectFromStorage();
|
|
63
|
+
return stored || redirectUrl || fallbackUrl;
|
|
32
64
|
};
|
|
33
65
|
|
|
34
66
|
const useAndClearRedirect = () => {
|
|
35
|
-
|
|
67
|
+
// Read directly from storage to ensure we get the latest saved URL
|
|
68
|
+
// even if it was saved by a different component instance
|
|
69
|
+
const stored = getRedirectFromStorage();
|
|
70
|
+
const finalUrl = stored || redirectUrl || fallbackUrl;
|
|
71
|
+
|
|
36
72
|
if (clearOnUse) {
|
|
37
73
|
clearRedirect();
|
|
38
74
|
}
|