@logto/react 0.1.11 → 0.1.14
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 +14 -9
- package/package.json +4 -4
package/lib/hooks/index.js
CHANGED
|
@@ -25,11 +25,12 @@ 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
|
};
|
|
31
32
|
const useHandleSignInCallback = (returnToPageUrl = window.location.origin) => {
|
|
32
|
-
const { logtoClient, isAuthenticated, error
|
|
33
|
+
const { logtoClient, isAuthenticated, error } = (0, react_1.useContext)(context_1.LogtoContext);
|
|
33
34
|
const { isLoading, setLoadingState } = useLoadingState();
|
|
34
35
|
const { handleError } = useErrorHandler();
|
|
35
36
|
const handleSignInCallback = (0, react_1.useCallback)(async (callbackUri) => {
|
|
@@ -39,7 +40,9 @@ const useHandleSignInCallback = (returnToPageUrl = window.location.origin) => {
|
|
|
39
40
|
try {
|
|
40
41
|
setLoadingState(true);
|
|
41
42
|
await logtoClient.handleSignInCallback(callbackUri);
|
|
42
|
-
|
|
43
|
+
// We deliberately do NOT set isAuthenticated to true here, because the app state may change immediately
|
|
44
|
+
// even before navigating to the return page URL, which might cause rendering problems.
|
|
45
|
+
// Moreover, since the location will be redirected, the isAuthenticated state will not matter any more.
|
|
43
46
|
window.location.assign(returnToPageUrl);
|
|
44
47
|
}
|
|
45
48
|
catch (error) {
|
|
@@ -48,7 +51,7 @@ const useHandleSignInCallback = (returnToPageUrl = window.location.origin) => {
|
|
|
48
51
|
finally {
|
|
49
52
|
setLoadingState(false);
|
|
50
53
|
}
|
|
51
|
-
}, [logtoClient, returnToPageUrl,
|
|
54
|
+
}, [logtoClient, returnToPageUrl, setLoadingState, handleError]);
|
|
52
55
|
(0, react_1.useEffect)(() => {
|
|
53
56
|
if (!isAuthenticated && logtoClient?.isSignInRedirected(window.location.href)) {
|
|
54
57
|
void handleSignInCallback(window.location.href);
|
|
@@ -62,7 +65,7 @@ const useHandleSignInCallback = (returnToPageUrl = window.location.origin) => {
|
|
|
62
65
|
};
|
|
63
66
|
exports.useHandleSignInCallback = useHandleSignInCallback;
|
|
64
67
|
const useLogto = () => {
|
|
65
|
-
const { logtoClient, loadingCount, isAuthenticated, error
|
|
68
|
+
const { logtoClient, loadingCount, isAuthenticated, error } = (0, react_1.useContext)(context_1.LogtoContext);
|
|
66
69
|
const { setLoadingState } = useLoadingState();
|
|
67
70
|
const { handleError } = useErrorHandler();
|
|
68
71
|
const isLoading = loadingCount > 0;
|
|
@@ -88,7 +91,9 @@ const useLogto = () => {
|
|
|
88
91
|
try {
|
|
89
92
|
setLoadingState(true);
|
|
90
93
|
await logtoClient.signOut(postLogoutRedirectUri);
|
|
91
|
-
|
|
94
|
+
// We deliberately do NOT set isAuthenticated to false here, because the app state may change immediately
|
|
95
|
+
// even before navigating to the oidc end session endpoint, which might cause rendering problems.
|
|
96
|
+
// Moreover, since the location will be redirected, the isAuthenticated state will not matter any more.
|
|
92
97
|
}
|
|
93
98
|
catch (error) {
|
|
94
99
|
handleError(error, 'Unexpected error occurred while signing out.');
|
|
@@ -96,7 +101,7 @@ const useLogto = () => {
|
|
|
96
101
|
finally {
|
|
97
102
|
setLoadingState(false);
|
|
98
103
|
}
|
|
99
|
-
}, [logtoClient,
|
|
104
|
+
}, [logtoClient, setLoadingState, handleError]);
|
|
100
105
|
const fetchUserInfo = (0, react_1.useCallback)(async () => {
|
|
101
106
|
if (!logtoClient) {
|
|
102
107
|
return (0, context_1.throwContextError)();
|
|
@@ -134,10 +139,10 @@ const useLogto = () => {
|
|
|
134
139
|
try {
|
|
135
140
|
return logtoClient.getIdTokenClaims();
|
|
136
141
|
}
|
|
137
|
-
catch
|
|
138
|
-
|
|
142
|
+
catch {
|
|
143
|
+
// Do nothing if any exception occurs. Caller will get undefined value.
|
|
139
144
|
}
|
|
140
|
-
}, [logtoClient
|
|
145
|
+
}, [logtoClient]);
|
|
141
146
|
if (!logtoClient) {
|
|
142
147
|
return (0, context_1.throwContextError)();
|
|
143
148
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"exports": "./lib/index.js",
|
|
6
6
|
"typings": "./lib/index.d.ts",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"prepack": "pnpm test"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@logto/browser": "^0.1.
|
|
27
|
+
"@logto/browser": "^0.1.14",
|
|
28
28
|
"@silverhand/essentials": "^1.1.6"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@types/react": "^17.0.39",
|
|
39
39
|
"eslint": "^8.9.0",
|
|
40
40
|
"jest": "^27.5.1",
|
|
41
|
-
"lint-staged": "^
|
|
41
|
+
"lint-staged": "^13.0.0",
|
|
42
42
|
"postcss": "^8.4.6",
|
|
43
43
|
"prettier": "^2.5.1",
|
|
44
44
|
"react": "^17.0.2",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"publishConfig": {
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "5d05c6bd23dc35d7217031edccc01db2bae33b7b"
|
|
60
60
|
}
|