@logto/react 2.0.1 → 2.1.1
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.cjs +11 -4
- package/lib/hooks/index.js +11 -4
- package/lib/provider.cjs +2 -2
- package/lib/provider.d.ts +6 -1
- package/lib/provider.js +2 -2
- package/package.json +2 -2
package/lib/hooks/index.cjs
CHANGED
|
@@ -56,10 +56,17 @@ const useHandleSignInCallback = (callback) => {
|
|
|
56
56
|
}
|
|
57
57
|
}, [logtoClient, setLoadingState, setIsAuthenticated, handleError]);
|
|
58
58
|
react.useEffect(() => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
if (!logtoClient) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
(async () => {
|
|
63
|
+
const currentPageUrl = window.location.href;
|
|
64
|
+
const isAuthenticated = await logtoClient.isAuthenticated();
|
|
65
|
+
const isRedirected = await logtoClient.isSignInRedirected(currentPageUrl);
|
|
66
|
+
if (!isAuthenticated && isRedirected) {
|
|
67
|
+
void handleSignInCallback(currentPageUrl);
|
|
68
|
+
}
|
|
69
|
+
})();
|
|
63
70
|
}, [handleSignInCallback, isAuthenticated, logtoClient]);
|
|
64
71
|
return {
|
|
65
72
|
isLoading,
|
package/lib/hooks/index.js
CHANGED
|
@@ -54,10 +54,17 @@ const useHandleSignInCallback = (callback) => {
|
|
|
54
54
|
}
|
|
55
55
|
}, [logtoClient, setLoadingState, setIsAuthenticated, handleError]);
|
|
56
56
|
useEffect(() => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
if (!logtoClient) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
(async () => {
|
|
61
|
+
const currentPageUrl = window.location.href;
|
|
62
|
+
const isAuthenticated = await logtoClient.isAuthenticated();
|
|
63
|
+
const isRedirected = await logtoClient.isSignInRedirected(currentPageUrl);
|
|
64
|
+
if (!isAuthenticated && isRedirected) {
|
|
65
|
+
void handleSignInCallback(currentPageUrl);
|
|
66
|
+
}
|
|
67
|
+
})();
|
|
61
68
|
}, [handleSignInCallback, isAuthenticated, logtoClient]);
|
|
62
69
|
return {
|
|
63
70
|
isLoading,
|
package/lib/provider.cjs
CHANGED
|
@@ -9,9 +9,9 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
9
9
|
|
|
10
10
|
var LogtoClient__default = /*#__PURE__*/_interopDefault(LogtoClient);
|
|
11
11
|
|
|
12
|
-
const LogtoProvider = ({ config, children }) => {
|
|
12
|
+
const LogtoProvider = ({ config, children, unstable_enableCache = false, }) => {
|
|
13
13
|
const [loadingCount, setLoadingCount] = react.useState(1);
|
|
14
|
-
const memorizedLogtoClient = react.useMemo(() => ({ logtoClient: new LogtoClient__default.default(config) }), [config]);
|
|
14
|
+
const memorizedLogtoClient = react.useMemo(() => ({ logtoClient: new LogtoClient__default.default(config, unstable_enableCache) }), [config, unstable_enableCache]);
|
|
15
15
|
const [isAuthenticated, setIsAuthenticated] = react.useState(false);
|
|
16
16
|
const [error, setError] = react.useState();
|
|
17
17
|
react.useEffect(() => {
|
package/lib/provider.d.ts
CHANGED
|
@@ -2,6 +2,11 @@ import { type LogtoConfig } from '@logto/browser';
|
|
|
2
2
|
import { type ReactNode } from 'react';
|
|
3
3
|
export type LogtoProviderProps = {
|
|
4
4
|
config: LogtoConfig;
|
|
5
|
+
/**
|
|
6
|
+
* Whether to enable cache for well-known data. Use sessionStorage by default.
|
|
7
|
+
* @default false
|
|
8
|
+
*/
|
|
9
|
+
unstable_enableCache?: boolean;
|
|
5
10
|
children?: ReactNode;
|
|
6
11
|
};
|
|
7
|
-
export declare const LogtoProvider: ({ config, children }: LogtoProviderProps) => JSX.Element;
|
|
12
|
+
export declare const LogtoProvider: ({ config, children, unstable_enableCache, }: LogtoProviderProps) => JSX.Element;
|
package/lib/provider.js
CHANGED
|
@@ -3,9 +3,9 @@ import LogtoClient from '@logto/browser';
|
|
|
3
3
|
import { useState, useMemo, useEffect } from 'react';
|
|
4
4
|
import { LogtoContext } from './context.js';
|
|
5
5
|
|
|
6
|
-
const LogtoProvider = ({ config, children }) => {
|
|
6
|
+
const LogtoProvider = ({ config, children, unstable_enableCache = false, }) => {
|
|
7
7
|
const [loadingCount, setLoadingCount] = useState(1);
|
|
8
|
-
const memorizedLogtoClient = useMemo(() => ({ logtoClient: new LogtoClient(config) }), [config]);
|
|
8
|
+
const memorizedLogtoClient = useMemo(() => ({ logtoClient: new LogtoClient(config, unstable_enableCache) }), [config, unstable_enableCache]);
|
|
9
9
|
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
|
10
10
|
const [error, setError] = useState();
|
|
11
11
|
useEffect(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/react",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./lib/index.cjs",
|
|
6
6
|
"module": "./lib/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"directory": "packages/react"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@logto/browser": "^2.
|
|
24
|
+
"@logto/browser": "^2.1.0",
|
|
25
25
|
"@silverhand/essentials": "^2.6.2"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|