@logto/react 0.1.7 → 0.1.10
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 +2 -1
- package/lib/index.js +5 -1
- package/package.json +3 -3
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,5 @@
|
|
|
1
1
|
export type { LogtoContextProps } from './context';
|
|
2
|
-
export type { LogtoConfig, IdTokenClaims, UserInfoResponse } from '@logto/browser';
|
|
2
|
+
export type { LogtoConfig, IdTokenClaims, UserInfoResponse, LogtoErrorCode, LogtoClientErrorCode, } from '@logto/browser';
|
|
3
|
+
export { LogtoError, LogtoClientError, OidcError } from '@logto/browser';
|
|
3
4
|
export * from './provider';
|
|
4
5
|
export { useLogto, useHandleSignInCallback } from './hooks';
|
package/lib/index.js
CHANGED
|
@@ -14,7 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.useHandleSignInCallback = exports.useLogto = void 0;
|
|
17
|
+
exports.useHandleSignInCallback = exports.useLogto = exports.OidcError = exports.LogtoClientError = exports.LogtoError = void 0;
|
|
18
|
+
var browser_1 = require("@logto/browser");
|
|
19
|
+
Object.defineProperty(exports, "LogtoError", { enumerable: true, get: function () { return browser_1.LogtoError; } });
|
|
20
|
+
Object.defineProperty(exports, "LogtoClientError", { enumerable: true, get: function () { return browser_1.LogtoClientError; } });
|
|
21
|
+
Object.defineProperty(exports, "OidcError", { enumerable: true, get: function () { return browser_1.OidcError; } });
|
|
18
22
|
__exportStar(require("./provider"), exports);
|
|
19
23
|
var hooks_1 = require("./hooks");
|
|
20
24
|
Object.defineProperty(exports, "useLogto", { enumerable: true, get: function () { return hooks_1.useLogto; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
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.10",
|
|
28
28
|
"@silverhand/essentials": "^1.1.6"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"publishConfig": {
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "ea6c7b435be8f74baf7fb76336bc0ca7cb7304c4"
|
|
60
60
|
}
|