@logto/react 0.1.11 → 0.1.12
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/lib/hooks/index.js +9 -6
- package/package.json +2 -2
package/lib/hooks/index.js
CHANGED
|
@@ -25,6 +25,7 @@ const useErrorHandler = () => {
|
|
|
25
25
|
else if (fallbackErrorMessage) {
|
|
26
26
|
setError(new Error(fallbackErrorMessage));
|
|
27
27
|
}
|
|
28
|
+
console.error(error);
|
|
28
29
|
}, [setError]);
|
|
29
30
|
return { handleError };
|
|
30
31
|
};
|
|
@@ -62,7 +63,7 @@ const useHandleSignInCallback = (returnToPageUrl = window.location.origin) => {
|
|
|
62
63
|
};
|
|
63
64
|
exports.useHandleSignInCallback = useHandleSignInCallback;
|
|
64
65
|
const useLogto = () => {
|
|
65
|
-
const { logtoClient, loadingCount, isAuthenticated, error
|
|
66
|
+
const { logtoClient, loadingCount, isAuthenticated, error } = (0, react_1.useContext)(context_1.LogtoContext);
|
|
66
67
|
const { setLoadingState } = useLoadingState();
|
|
67
68
|
const { handleError } = useErrorHandler();
|
|
68
69
|
const isLoading = loadingCount > 0;
|
|
@@ -88,7 +89,9 @@ const useLogto = () => {
|
|
|
88
89
|
try {
|
|
89
90
|
setLoadingState(true);
|
|
90
91
|
await logtoClient.signOut(postLogoutRedirectUri);
|
|
91
|
-
|
|
92
|
+
// We deliberately do NOT set isAuthenticated to false here, because the app state may change immediately
|
|
93
|
+
// even before navigating to the oidc end session endpoint, which might cause rendering problems.
|
|
94
|
+
// Instead, we will reload isAuthenticated state when the user is redirected back to the app.
|
|
92
95
|
}
|
|
93
96
|
catch (error) {
|
|
94
97
|
handleError(error, 'Unexpected error occurred while signing out.');
|
|
@@ -96,7 +99,7 @@ const useLogto = () => {
|
|
|
96
99
|
finally {
|
|
97
100
|
setLoadingState(false);
|
|
98
101
|
}
|
|
99
|
-
}, [logtoClient,
|
|
102
|
+
}, [logtoClient, setLoadingState, handleError]);
|
|
100
103
|
const fetchUserInfo = (0, react_1.useCallback)(async () => {
|
|
101
104
|
if (!logtoClient) {
|
|
102
105
|
return (0, context_1.throwContextError)();
|
|
@@ -134,10 +137,10 @@ const useLogto = () => {
|
|
|
134
137
|
try {
|
|
135
138
|
return logtoClient.getIdTokenClaims();
|
|
136
139
|
}
|
|
137
|
-
catch
|
|
138
|
-
|
|
140
|
+
catch {
|
|
141
|
+
// Do nothing if any exception occurs. Caller will get undefined value.
|
|
139
142
|
}
|
|
140
|
-
}, [logtoClient
|
|
143
|
+
}, [logtoClient]);
|
|
141
144
|
if (!logtoClient) {
|
|
142
145
|
return (0, context_1.throwContextError)();
|
|
143
146
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"exports": "./lib/index.js",
|
|
6
6
|
"typings": "./lib/index.d.ts",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"publishConfig": {
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "1e7449daf62edac7f7dd2eb37f3e5b83e6bf3c56"
|
|
60
60
|
}
|