@logto/react 2.1.0 → 2.1.2

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/README.md CHANGED
@@ -5,8 +5,6 @@
5
5
 
6
6
  The Logto React SDK written in TypeScript. Check out our [integration guide](https://docs.logto.io/docs/recipes/integrate-logto/react) or [docs](https://docs.logto.io/sdk/JavaScript/react/) for more information.
7
7
 
8
- We also provide [集成指南](https://docs.logto.io/zh-cn/docs/recipes/integrate-logto/react/) and [文档](https://docs.logto.io/zh-cn/sdk/JavaScript/react/) in Simplified Chinese.
9
-
10
8
  ## Installation
11
9
 
12
10
  ### Using npm
@@ -56,10 +56,17 @@ const useHandleSignInCallback = (callback) => {
56
56
  }
57
57
  }, [logtoClient, setLoadingState, setIsAuthenticated, handleError]);
58
58
  react.useEffect(() => {
59
- const currentPageUrl = window.location.href;
60
- if (!isAuthenticated && logtoClient?.isSignInRedirected(currentPageUrl)) {
61
- void handleSignInCallback(currentPageUrl);
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,
@@ -54,10 +54,17 @@ const useHandleSignInCallback = (callback) => {
54
54
  }
55
55
  }, [logtoClient, setLoadingState, setIsAuthenticated, handleError]);
56
56
  useEffect(() => {
57
- const currentPageUrl = window.location.href;
58
- if (!isAuthenticated && logtoClient?.isSignInRedirected(currentPageUrl)) {
59
- void handleSignInCallback(currentPageUrl);
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/index.cjs CHANGED
@@ -14,6 +14,10 @@ Object.defineProperty(exports, 'LogtoError', {
14
14
  enumerable: true,
15
15
  get: function () { return LogtoClient.LogtoError; }
16
16
  });
17
+ Object.defineProperty(exports, 'LogtoRequestError', {
18
+ enumerable: true,
19
+ get: function () { return LogtoClient.LogtoRequestError; }
20
+ });
17
21
  Object.defineProperty(exports, 'OidcError', {
18
22
  enumerable: true,
19
23
  get: function () { return LogtoClient.OidcError; }
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export type { LogtoContextProps } from './context.js';
2
2
  export type { LogtoConfig, IdTokenClaims, UserInfoResponse, LogtoErrorCode, LogtoClientErrorCode, InteractionMode, } from '@logto/browser';
3
- export { LogtoError, LogtoClientError, OidcError, Prompt, ReservedScope, UserScope, } from '@logto/browser';
3
+ export { LogtoError, LogtoClientError, LogtoRequestError, OidcError, Prompt, ReservedScope, UserScope, } from '@logto/browser';
4
4
  export * from './provider.js';
5
5
  export { useLogto, useHandleSignInCallback } from './hooks/index.js';
package/lib/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export { LogtoClientError, LogtoError, OidcError, Prompt, ReservedScope, UserScope } from '@logto/browser';
1
+ export { LogtoClientError, LogtoError, LogtoRequestError, OidcError, Prompt, ReservedScope, UserScope } from '@logto/browser';
2
2
  export { LogtoProvider } from './provider.js';
3
3
  export { useHandleSignInCallback, useLogto } from './hooks/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logto/react",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "type": "module",
5
5
  "main": "./lib/index.cjs",
6
6
  "module": "./lib/index.js",
@@ -21,24 +21,24 @@
21
21
  "directory": "packages/react"
22
22
  },
23
23
  "dependencies": {
24
- "@logto/browser": "^2.1.0",
24
+ "@logto/browser": "^2.1.2",
25
25
  "@silverhand/essentials": "^2.6.2"
26
26
  },
27
27
  "devDependencies": {
28
- "@silverhand/eslint-config": "^3.0.1",
29
- "@silverhand/eslint-config-react": "^3.0.1",
30
- "@silverhand/ts-config": "^3.0.0",
31
- "@silverhand/ts-config-react": "^3.0.0",
28
+ "@silverhand/eslint-config": "^4.0.1",
29
+ "@silverhand/eslint-config-react": "^4.0.1",
30
+ "@silverhand/ts-config": "^4.0.0",
31
+ "@silverhand/ts-config-react": "^4.0.0",
32
32
  "@swc/core": "^1.3.50",
33
33
  "@swc/jest": "^0.2.24",
34
34
  "@testing-library/react": "^14.0.0",
35
35
  "@types/jest": "^29.5.0",
36
36
  "@types/react": "^18.2.0",
37
- "eslint": "^8.38.0",
37
+ "eslint": "^8.44.0",
38
38
  "jest": "^29.5.0",
39
- "lint-staged": "^13.0.0",
39
+ "lint-staged": "^14.0.0",
40
40
  "postcss": "^8.4.6",
41
- "prettier": "^2.8.7",
41
+ "prettier": "^3.0.0",
42
42
  "react": "^18.0.2",
43
43
  "stylelint": "^15.0.0",
44
44
  "typescript": "^5.0.0"