@logto/react 0.1.7 → 0.1.8
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.d.ts +1 -0
- package/lib/hooks/index.js +8 -7
- package/lib/index.d.ts +1 -1
- package/package.json +2 -2
package/lib/hooks/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ declare type Logto = {
|
|
|
12
12
|
declare const useHandleSignInCallback: (returnToPageUrl?: string) => {
|
|
13
13
|
isLoading: boolean;
|
|
14
14
|
isAuthenticated: boolean;
|
|
15
|
+
error: Error | undefined;
|
|
15
16
|
};
|
|
16
17
|
declare const useLogto: () => Logto;
|
|
17
18
|
export { useLogto, useHandleSignInCallback };
|
package/lib/hooks/index.js
CHANGED
|
@@ -29,17 +29,18 @@ const useErrorHandler = () => {
|
|
|
29
29
|
return { handleError };
|
|
30
30
|
};
|
|
31
31
|
const useHandleSignInCallback = (returnToPageUrl = window.location.origin) => {
|
|
32
|
-
const { logtoClient, isAuthenticated, setIsAuthenticated } = (0, react_1.useContext)(context_1.LogtoContext);
|
|
32
|
+
const { logtoClient, isAuthenticated, error, setIsAuthenticated } = (0, react_1.useContext)(context_1.LogtoContext);
|
|
33
33
|
const { isLoading, setLoadingState } = useLoadingState();
|
|
34
34
|
const { handleError } = useErrorHandler();
|
|
35
35
|
const handleSignInCallback = (0, react_1.useCallback)(async (callbackUri) => {
|
|
36
36
|
if (!logtoClient) {
|
|
37
37
|
return (0, context_1.throwContextError)();
|
|
38
38
|
}
|
|
39
|
-
setLoadingState(true);
|
|
40
39
|
try {
|
|
40
|
+
setLoadingState(true);
|
|
41
41
|
await logtoClient.handleSignInCallback(callbackUri);
|
|
42
42
|
setIsAuthenticated(true);
|
|
43
|
+
window.location.assign(returnToPageUrl);
|
|
43
44
|
}
|
|
44
45
|
catch (error) {
|
|
45
46
|
handleError(error, 'Unexpected error occurred while handling sign in callback.');
|
|
@@ -47,7 +48,6 @@ const useHandleSignInCallback = (returnToPageUrl = window.location.origin) => {
|
|
|
47
48
|
finally {
|
|
48
49
|
setLoadingState(false);
|
|
49
50
|
}
|
|
50
|
-
window.location.assign(returnToPageUrl);
|
|
51
51
|
}, [logtoClient, returnToPageUrl, setIsAuthenticated, setLoadingState, handleError]);
|
|
52
52
|
(0, react_1.useEffect)(() => {
|
|
53
53
|
if (!isAuthenticated && logtoClient?.isSignInRedirected(window.location.href)) {
|
|
@@ -57,6 +57,7 @@ const useHandleSignInCallback = (returnToPageUrl = window.location.origin) => {
|
|
|
57
57
|
return {
|
|
58
58
|
isLoading,
|
|
59
59
|
isAuthenticated,
|
|
60
|
+
error,
|
|
60
61
|
};
|
|
61
62
|
};
|
|
62
63
|
exports.useHandleSignInCallback = useHandleSignInCallback;
|
|
@@ -69,8 +70,8 @@ const useLogto = () => {
|
|
|
69
70
|
if (!logtoClient) {
|
|
70
71
|
return (0, context_1.throwContextError)();
|
|
71
72
|
}
|
|
72
|
-
setLoadingState(true);
|
|
73
73
|
try {
|
|
74
|
+
setLoadingState(true);
|
|
74
75
|
await logtoClient.signIn(redirectUri);
|
|
75
76
|
}
|
|
76
77
|
catch (error) {
|
|
@@ -84,8 +85,8 @@ const useLogto = () => {
|
|
|
84
85
|
if (!logtoClient) {
|
|
85
86
|
return (0, context_1.throwContextError)();
|
|
86
87
|
}
|
|
87
|
-
setLoadingState(true);
|
|
88
88
|
try {
|
|
89
|
+
setLoadingState(true);
|
|
89
90
|
await logtoClient.signOut(postLogoutRedirectUri);
|
|
90
91
|
setIsAuthenticated(false);
|
|
91
92
|
}
|
|
@@ -100,8 +101,8 @@ const useLogto = () => {
|
|
|
100
101
|
if (!logtoClient) {
|
|
101
102
|
return (0, context_1.throwContextError)();
|
|
102
103
|
}
|
|
103
|
-
setLoadingState(true);
|
|
104
104
|
try {
|
|
105
|
+
setLoadingState(true);
|
|
105
106
|
return await logtoClient.fetchUserInfo();
|
|
106
107
|
}
|
|
107
108
|
catch (error) {
|
|
@@ -115,8 +116,8 @@ const useLogto = () => {
|
|
|
115
116
|
if (!logtoClient) {
|
|
116
117
|
return (0, context_1.throwContextError)();
|
|
117
118
|
}
|
|
118
|
-
setLoadingState(true);
|
|
119
119
|
try {
|
|
120
|
+
setLoadingState(true);
|
|
120
121
|
return await logtoClient.getAccessToken(resource);
|
|
121
122
|
}
|
|
122
123
|
catch (error) {
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export type { LogtoContextProps } from './context';
|
|
2
|
-
export type { LogtoConfig, IdTokenClaims, UserInfoResponse } from '@logto/browser';
|
|
2
|
+
export type { LogtoConfig, IdTokenClaims, UserInfoResponse, LogtoClientError, LogtoClientErrorCode, } from '@logto/browser';
|
|
3
3
|
export * from './provider';
|
|
4
4
|
export { useLogto, useHandleSignInCallback } from './hooks';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
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": "8adf9495676b65649b093f9e8b460a1568e08e0a"
|
|
60
60
|
}
|