@authu/react 1.0.37 → 1.0.39
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/AuthUProvider.d.ts.map +1 -1
- package/dist/AuthUProvider.js +16 -13
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthUProvider.d.ts","sourceRoot":"","sources":["../src/AuthUProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EAGlB,MAAM,YAAY,CAAC;AAgBpB,eAAO,MAAM,YAAY,mDAAgD,CAAC;AAO1E,UAAU,kBAAkB;IAC1B,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAID,wBAAgB,aAAa,CAAC,EAAC,MAAM,EAAE,QAAQ,EAAC,EAAE,kBAAkB,
|
|
1
|
+
{"version":3,"file":"AuthUProvider.d.ts","sourceRoot":"","sources":["../src/AuthUProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EAGlB,MAAM,YAAY,CAAC;AAgBpB,eAAO,MAAM,YAAY,mDAAgD,CAAC;AAO1E,UAAU,kBAAkB;IAC1B,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAID,wBAAgB,aAAa,CAAC,EAAC,MAAM,EAAE,QAAQ,EAAC,EAAE,kBAAkB,2CAiVnE"}
|
package/dist/AuthUProvider.js
CHANGED
|
@@ -37,11 +37,7 @@ export function AuthUProvider({ config, children }) {
|
|
|
37
37
|
});
|
|
38
38
|
return `${buildBaseUrl(config.domain)}/authorize?${params.toString()}`;
|
|
39
39
|
}, [config]);
|
|
40
|
-
const
|
|
41
|
-
const codeVerifier = getCodeVerifier();
|
|
42
|
-
if (!codeVerifier) {
|
|
43
|
-
throw new Error('No code verifier found');
|
|
44
|
-
}
|
|
40
|
+
const exchangeCodeForTokensWithVerifier = useCallback(async (code, codeVerifier) => {
|
|
45
41
|
const response = await fetch(`${buildBaseUrl(config.domain)}/oauth/token`, {
|
|
46
42
|
method: 'POST',
|
|
47
43
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -57,11 +53,7 @@ export function AuthUProvider({ config, children }) {
|
|
|
57
53
|
const error = await response.json();
|
|
58
54
|
throw new Error(error.error_description || 'Token exchange failed');
|
|
59
55
|
}
|
|
60
|
-
|
|
61
|
-
clearCodeVerifier();
|
|
62
|
-
clearState();
|
|
63
|
-
clearNonce();
|
|
64
|
-
return tokens;
|
|
56
|
+
return response.json();
|
|
65
57
|
}, [config]);
|
|
66
58
|
const parseIdToken = (idToken) => {
|
|
67
59
|
const parts = idToken.split('.');
|
|
@@ -189,8 +181,20 @@ export function AuthUProvider({ config, children }) {
|
|
|
189
181
|
}));
|
|
190
182
|
return;
|
|
191
183
|
}
|
|
184
|
+
// Get and immediately clear code verifier to prevent duplicate exchanges
|
|
185
|
+
// (React StrictMode double-mount protection)
|
|
186
|
+
const codeVerifier = getCodeVerifier();
|
|
187
|
+
if (!codeVerifier) {
|
|
188
|
+
console.log('[AuthU SDK] No code verifier found, skipping duplicate callback');
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
clearCodeVerifier();
|
|
192
|
+
clearState();
|
|
193
|
+
clearNonce();
|
|
194
|
+
// Clear URL immediately to prevent issues on refresh
|
|
195
|
+
window.history.replaceState({}, document.title, window.location.pathname);
|
|
192
196
|
try {
|
|
193
|
-
const tokens = await
|
|
197
|
+
const tokens = await exchangeCodeForTokensWithVerifier(code, codeVerifier);
|
|
194
198
|
const user = parseIdToken(tokens.id_token);
|
|
195
199
|
const expiresAt = Date.now() + tokens.expires_in * 1000;
|
|
196
200
|
localStorage.setItem(TOKEN_STORAGE_KEY, JSON.stringify({
|
|
@@ -207,7 +211,6 @@ export function AuthUProvider({ config, children }) {
|
|
|
207
211
|
expiresAt,
|
|
208
212
|
error: null
|
|
209
213
|
});
|
|
210
|
-
window.history.replaceState({}, document.title, window.location.pathname);
|
|
211
214
|
}
|
|
212
215
|
catch (err) {
|
|
213
216
|
setState(prev => ({
|
|
@@ -248,7 +251,7 @@ export function AuthUProvider({ config, children }) {
|
|
|
248
251
|
setState(prev => ({ ...prev, isLoading: false }));
|
|
249
252
|
};
|
|
250
253
|
handleCallback();
|
|
251
|
-
}, [
|
|
254
|
+
}, [exchangeCodeForTokensWithVerifier, fetchUserInfo]);
|
|
252
255
|
const contextValue = {
|
|
253
256
|
isLoading: state.isLoading,
|
|
254
257
|
isAuthenticated: state.isAuthenticated,
|