@logto/react 1.1.2 → 2.0.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.
@@ -1,9 +1,11 @@
1
- import { createContext } from 'react';
1
+ 'use strict';
2
+
3
+ var react = require('react');
2
4
 
3
5
  const throwContextError = () => {
4
6
  throw new Error('Must be used inside <LogtoProvider> context.');
5
7
  };
6
- const LogtoContext = createContext({
8
+ const LogtoContext = react.createContext({
7
9
  logtoClient: undefined,
8
10
  isAuthenticated: false,
9
11
  loadingCount: 0,
@@ -13,4 +15,5 @@ const LogtoContext = createContext({
13
15
  setError: throwContextError,
14
16
  });
15
17
 
16
- export { LogtoContext, throwContextError };
18
+ exports.LogtoContext = LogtoContext;
19
+ exports.throwContextError = throwContextError;
package/lib/context.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import LogtoClient from '@logto/browser';
2
+ import type LogtoClient from '@logto/browser';
3
3
  export type LogtoContextProps = {
4
4
  logtoClient?: LogtoClient;
5
5
  isAuthenticated: boolean;
package/lib/context.js CHANGED
@@ -1,11 +1,9 @@
1
- 'use strict';
2
-
3
- var react = require('react');
1
+ import { createContext } from 'react';
4
2
 
5
3
  const throwContextError = () => {
6
4
  throw new Error('Must be used inside <LogtoProvider> context.');
7
5
  };
8
- const LogtoContext = react.createContext({
6
+ const LogtoContext = createContext({
9
7
  logtoClient: undefined,
10
8
  isAuthenticated: false,
11
9
  loadingCount: 0,
@@ -15,5 +13,4 @@ const LogtoContext = react.createContext({
15
13
  setError: throwContextError,
16
14
  });
17
15
 
18
- exports.LogtoContext = LogtoContext;
19
- exports.throwContextError = throwContextError;
16
+ export { LogtoContext, throwContextError };
@@ -1,10 +1,12 @@
1
- import { useContext, useRef, useEffect, useCallback } from 'react';
2
- import { LogtoContext, throwContextError } from '../context.mjs';
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var context = require('../context.cjs');
3
5
 
4
6
  const useLoadingState = () => {
5
- const { loadingCount, setLoadingCount } = useContext(LogtoContext);
7
+ const { loadingCount, setLoadingCount } = react.useContext(context.LogtoContext);
6
8
  const isLoading = loadingCount > 0;
7
- const setLoadingState = useCallback((state) => {
9
+ const setLoadingState = react.useCallback((state) => {
8
10
  if (state) {
9
11
  setLoadingCount((count) => count + 1);
10
12
  }
@@ -15,8 +17,8 @@ const useLoadingState = () => {
15
17
  return { isLoading, setLoadingState };
16
18
  };
17
19
  const useErrorHandler = () => {
18
- const { setError } = useContext(LogtoContext);
19
- const handleError = useCallback((error, fallbackErrorMessage) => {
20
+ const { setError } = react.useContext(context.LogtoContext);
21
+ const handleError = react.useCallback((error, fallbackErrorMessage) => {
20
22
  if (error instanceof Error) {
21
23
  setError(error);
22
24
  }
@@ -28,17 +30,17 @@ const useErrorHandler = () => {
28
30
  return { handleError };
29
31
  };
30
32
  const useHandleSignInCallback = (callback) => {
31
- const { logtoClient, isAuthenticated, error, setIsAuthenticated } = useContext(LogtoContext);
33
+ const { logtoClient, isAuthenticated, error, setIsAuthenticated } = react.useContext(context.LogtoContext);
32
34
  const { isLoading, setLoadingState } = useLoadingState();
33
35
  const { handleError } = useErrorHandler();
34
- const callbackRef = useRef();
35
- useEffect(() => {
36
+ const callbackRef = react.useRef();
37
+ react.useEffect(() => {
36
38
  // eslint-disable-next-line @silverhand/fp/no-mutation
37
39
  callbackRef.current = callback; // Update ref to the latest callback.
38
40
  }, [callback]);
39
- const handleSignInCallback = useCallback(async (callbackUri) => {
41
+ const handleSignInCallback = react.useCallback(async (callbackUri) => {
40
42
  if (!logtoClient) {
41
- return throwContextError();
43
+ return context.throwContextError();
42
44
  }
43
45
  try {
44
46
  setLoadingState(true);
@@ -53,12 +55,12 @@ const useHandleSignInCallback = (callback) => {
53
55
  setLoadingState(false);
54
56
  }
55
57
  }, [logtoClient, setLoadingState, setIsAuthenticated, handleError]);
56
- useEffect(() => {
58
+ react.useEffect(() => {
57
59
  const currentPageUrl = window.location.href;
58
- if (!isAuthenticated && logtoClient?.isSignInRedirected(currentPageUrl) && !isLoading) {
60
+ if (!isAuthenticated && logtoClient?.isSignInRedirected(currentPageUrl)) {
59
61
  void handleSignInCallback(currentPageUrl);
60
62
  }
61
- }, [handleSignInCallback, isAuthenticated, isLoading, logtoClient]);
63
+ }, [handleSignInCallback, isAuthenticated, logtoClient]);
62
64
  return {
63
65
  isLoading,
64
66
  isAuthenticated,
@@ -66,13 +68,13 @@ const useHandleSignInCallback = (callback) => {
66
68
  };
67
69
  };
68
70
  const useLogto = () => {
69
- const { logtoClient, loadingCount, isAuthenticated, error } = useContext(LogtoContext);
71
+ const { logtoClient, loadingCount, isAuthenticated, error } = react.useContext(context.LogtoContext);
70
72
  const { setLoadingState } = useLoadingState();
71
73
  const { handleError } = useErrorHandler();
72
74
  const isLoading = loadingCount > 0;
73
- const signIn = useCallback(async (redirectUri, interactionMode) => {
75
+ const signIn = react.useCallback(async (redirectUri, interactionMode) => {
74
76
  if (!logtoClient) {
75
- return throwContextError();
77
+ return context.throwContextError();
76
78
  }
77
79
  try {
78
80
  setLoadingState(true);
@@ -82,9 +84,9 @@ const useLogto = () => {
82
84
  handleError(error, 'Unexpected error occurred while signing in.');
83
85
  }
84
86
  }, [logtoClient, setLoadingState, handleError]);
85
- const signOut = useCallback(async (postLogoutRedirectUri) => {
87
+ const signOut = react.useCallback(async (postLogoutRedirectUri) => {
86
88
  if (!logtoClient) {
87
- return throwContextError();
89
+ return context.throwContextError();
88
90
  }
89
91
  try {
90
92
  setLoadingState(true);
@@ -100,9 +102,9 @@ const useLogto = () => {
100
102
  setLoadingState(false);
101
103
  }
102
104
  }, [logtoClient, setLoadingState, handleError]);
103
- const fetchUserInfo = useCallback(async () => {
105
+ const fetchUserInfo = react.useCallback(async () => {
104
106
  if (!logtoClient) {
105
- return throwContextError();
107
+ return context.throwContextError();
106
108
  }
107
109
  try {
108
110
  setLoadingState(true);
@@ -115,9 +117,9 @@ const useLogto = () => {
115
117
  setLoadingState(false);
116
118
  }
117
119
  }, [logtoClient, setLoadingState, handleError]);
118
- const getAccessToken = useCallback(async (resource) => {
120
+ const getAccessToken = react.useCallback(async (resource) => {
119
121
  if (!logtoClient) {
120
- return throwContextError();
122
+ return context.throwContextError();
121
123
  }
122
124
  try {
123
125
  setLoadingState(true);
@@ -130,9 +132,9 @@ const useLogto = () => {
130
132
  setLoadingState(false);
131
133
  }
132
134
  }, [logtoClient, setLoadingState, handleError]);
133
- const getIdTokenClaims = useCallback(async () => {
135
+ const getIdTokenClaims = react.useCallback(async () => {
134
136
  if (!logtoClient) {
135
- return throwContextError();
137
+ return context.throwContextError();
136
138
  }
137
139
  try {
138
140
  return await logtoClient.getIdTokenClaims();
@@ -142,7 +144,7 @@ const useLogto = () => {
142
144
  }
143
145
  }, [logtoClient]);
144
146
  if (!logtoClient) {
145
- return throwContextError();
147
+ return context.throwContextError();
146
148
  }
147
149
  return {
148
150
  isAuthenticated,
@@ -156,4 +158,5 @@ const useLogto = () => {
156
158
  };
157
159
  };
158
160
 
159
- export { useHandleSignInCallback, useLogto };
161
+ exports.useHandleSignInCallback = useHandleSignInCallback;
162
+ exports.useLogto = useLogto;
@@ -1,4 +1,4 @@
1
- import { IdTokenClaims, InteractionMode, UserInfoResponse } from '@logto/browser';
1
+ import { type IdTokenClaims, type InteractionMode, type UserInfoResponse } from '@logto/browser';
2
2
  type Logto = {
3
3
  isAuthenticated: boolean;
4
4
  isLoading: boolean;
@@ -1,12 +1,10 @@
1
- 'use strict';
2
-
3
- var react = require('react');
4
- var context = require('../context.js');
1
+ import { useContext, useRef, useEffect, useCallback } from 'react';
2
+ import { LogtoContext, throwContextError } from '../context.js';
5
3
 
6
4
  const useLoadingState = () => {
7
- const { loadingCount, setLoadingCount } = react.useContext(context.LogtoContext);
5
+ const { loadingCount, setLoadingCount } = useContext(LogtoContext);
8
6
  const isLoading = loadingCount > 0;
9
- const setLoadingState = react.useCallback((state) => {
7
+ const setLoadingState = useCallback((state) => {
10
8
  if (state) {
11
9
  setLoadingCount((count) => count + 1);
12
10
  }
@@ -17,8 +15,8 @@ const useLoadingState = () => {
17
15
  return { isLoading, setLoadingState };
18
16
  };
19
17
  const useErrorHandler = () => {
20
- const { setError } = react.useContext(context.LogtoContext);
21
- const handleError = react.useCallback((error, fallbackErrorMessage) => {
18
+ const { setError } = useContext(LogtoContext);
19
+ const handleError = useCallback((error, fallbackErrorMessage) => {
22
20
  if (error instanceof Error) {
23
21
  setError(error);
24
22
  }
@@ -30,17 +28,17 @@ const useErrorHandler = () => {
30
28
  return { handleError };
31
29
  };
32
30
  const useHandleSignInCallback = (callback) => {
33
- const { logtoClient, isAuthenticated, error, setIsAuthenticated } = react.useContext(context.LogtoContext);
31
+ const { logtoClient, isAuthenticated, error, setIsAuthenticated } = useContext(LogtoContext);
34
32
  const { isLoading, setLoadingState } = useLoadingState();
35
33
  const { handleError } = useErrorHandler();
36
- const callbackRef = react.useRef();
37
- react.useEffect(() => {
34
+ const callbackRef = useRef();
35
+ useEffect(() => {
38
36
  // eslint-disable-next-line @silverhand/fp/no-mutation
39
37
  callbackRef.current = callback; // Update ref to the latest callback.
40
38
  }, [callback]);
41
- const handleSignInCallback = react.useCallback(async (callbackUri) => {
39
+ const handleSignInCallback = useCallback(async (callbackUri) => {
42
40
  if (!logtoClient) {
43
- return context.throwContextError();
41
+ return throwContextError();
44
42
  }
45
43
  try {
46
44
  setLoadingState(true);
@@ -55,12 +53,12 @@ const useHandleSignInCallback = (callback) => {
55
53
  setLoadingState(false);
56
54
  }
57
55
  }, [logtoClient, setLoadingState, setIsAuthenticated, handleError]);
58
- react.useEffect(() => {
56
+ useEffect(() => {
59
57
  const currentPageUrl = window.location.href;
60
- if (!isAuthenticated && logtoClient?.isSignInRedirected(currentPageUrl) && !isLoading) {
58
+ if (!isAuthenticated && logtoClient?.isSignInRedirected(currentPageUrl)) {
61
59
  void handleSignInCallback(currentPageUrl);
62
60
  }
63
- }, [handleSignInCallback, isAuthenticated, isLoading, logtoClient]);
61
+ }, [handleSignInCallback, isAuthenticated, logtoClient]);
64
62
  return {
65
63
  isLoading,
66
64
  isAuthenticated,
@@ -68,13 +66,13 @@ const useHandleSignInCallback = (callback) => {
68
66
  };
69
67
  };
70
68
  const useLogto = () => {
71
- const { logtoClient, loadingCount, isAuthenticated, error } = react.useContext(context.LogtoContext);
69
+ const { logtoClient, loadingCount, isAuthenticated, error } = useContext(LogtoContext);
72
70
  const { setLoadingState } = useLoadingState();
73
71
  const { handleError } = useErrorHandler();
74
72
  const isLoading = loadingCount > 0;
75
- const signIn = react.useCallback(async (redirectUri, interactionMode) => {
73
+ const signIn = useCallback(async (redirectUri, interactionMode) => {
76
74
  if (!logtoClient) {
77
- return context.throwContextError();
75
+ return throwContextError();
78
76
  }
79
77
  try {
80
78
  setLoadingState(true);
@@ -84,9 +82,9 @@ const useLogto = () => {
84
82
  handleError(error, 'Unexpected error occurred while signing in.');
85
83
  }
86
84
  }, [logtoClient, setLoadingState, handleError]);
87
- const signOut = react.useCallback(async (postLogoutRedirectUri) => {
85
+ const signOut = useCallback(async (postLogoutRedirectUri) => {
88
86
  if (!logtoClient) {
89
- return context.throwContextError();
87
+ return throwContextError();
90
88
  }
91
89
  try {
92
90
  setLoadingState(true);
@@ -102,9 +100,9 @@ const useLogto = () => {
102
100
  setLoadingState(false);
103
101
  }
104
102
  }, [logtoClient, setLoadingState, handleError]);
105
- const fetchUserInfo = react.useCallback(async () => {
103
+ const fetchUserInfo = useCallback(async () => {
106
104
  if (!logtoClient) {
107
- return context.throwContextError();
105
+ return throwContextError();
108
106
  }
109
107
  try {
110
108
  setLoadingState(true);
@@ -117,9 +115,9 @@ const useLogto = () => {
117
115
  setLoadingState(false);
118
116
  }
119
117
  }, [logtoClient, setLoadingState, handleError]);
120
- const getAccessToken = react.useCallback(async (resource) => {
118
+ const getAccessToken = useCallback(async (resource) => {
121
119
  if (!logtoClient) {
122
- return context.throwContextError();
120
+ return throwContextError();
123
121
  }
124
122
  try {
125
123
  setLoadingState(true);
@@ -132,9 +130,9 @@ const useLogto = () => {
132
130
  setLoadingState(false);
133
131
  }
134
132
  }, [logtoClient, setLoadingState, handleError]);
135
- const getIdTokenClaims = react.useCallback(async () => {
133
+ const getIdTokenClaims = useCallback(async () => {
136
134
  if (!logtoClient) {
137
- return context.throwContextError();
135
+ return throwContextError();
138
136
  }
139
137
  try {
140
138
  return await logtoClient.getIdTokenClaims();
@@ -144,7 +142,7 @@ const useLogto = () => {
144
142
  }
145
143
  }, [logtoClient]);
146
144
  if (!logtoClient) {
147
- return context.throwContextError();
145
+ return throwContextError();
148
146
  }
149
147
  return {
150
148
  isAuthenticated,
@@ -158,5 +156,4 @@ const useLogto = () => {
158
156
  };
159
157
  };
160
158
 
161
- exports.useHandleSignInCallback = useHandleSignInCallback;
162
- exports.useLogto = useLogto;
159
+ export { useHandleSignInCallback, useLogto };
package/lib/index.cjs ADDED
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ var LogtoClient = require('@logto/browser');
4
+ var provider = require('./provider.cjs');
5
+ var index = require('./hooks/index.cjs');
6
+
7
+
8
+
9
+ Object.defineProperty(exports, 'LogtoClientError', {
10
+ enumerable: true,
11
+ get: function () { return LogtoClient.LogtoClientError; }
12
+ });
13
+ Object.defineProperty(exports, 'LogtoError', {
14
+ enumerable: true,
15
+ get: function () { return LogtoClient.LogtoError; }
16
+ });
17
+ Object.defineProperty(exports, 'OidcError', {
18
+ enumerable: true,
19
+ get: function () { return LogtoClient.OidcError; }
20
+ });
21
+ Object.defineProperty(exports, 'Prompt', {
22
+ enumerable: true,
23
+ get: function () { return LogtoClient.Prompt; }
24
+ });
25
+ Object.defineProperty(exports, 'ReservedScope', {
26
+ enumerable: true,
27
+ get: function () { return LogtoClient.ReservedScope; }
28
+ });
29
+ Object.defineProperty(exports, 'UserScope', {
30
+ enumerable: true,
31
+ get: function () { return LogtoClient.UserScope; }
32
+ });
33
+ exports.LogtoProvider = provider.LogtoProvider;
34
+ exports.useHandleSignInCallback = index.useHandleSignInCallback;
35
+ exports.useLogto = index.useLogto;
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export type { LogtoContextProps } from './context';
1
+ export type { LogtoContextProps } from './context.js';
2
2
  export type { LogtoConfig, IdTokenClaims, UserInfoResponse, LogtoErrorCode, LogtoClientErrorCode, InteractionMode, } from '@logto/browser';
3
3
  export { LogtoError, LogtoClientError, OidcError, Prompt, ReservedScope, UserScope, } from '@logto/browser';
4
- export * from './provider';
5
- export { useLogto, useHandleSignInCallback } from './hooks';
4
+ export * from './provider.js';
5
+ export { useLogto, useHandleSignInCallback } from './hooks/index.js';
package/lib/index.js CHANGED
@@ -1,35 +1,3 @@
1
- 'use strict';
2
-
3
- var LogtoClient = require('@logto/browser');
4
- var provider = require('./provider.js');
5
- var index = require('./hooks/index.js');
6
-
7
-
8
-
9
- Object.defineProperty(exports, 'LogtoClientError', {
10
- enumerable: true,
11
- get: function () { return LogtoClient.LogtoClientError; }
12
- });
13
- Object.defineProperty(exports, 'LogtoError', {
14
- enumerable: true,
15
- get: function () { return LogtoClient.LogtoError; }
16
- });
17
- Object.defineProperty(exports, 'OidcError', {
18
- enumerable: true,
19
- get: function () { return LogtoClient.OidcError; }
20
- });
21
- Object.defineProperty(exports, 'Prompt', {
22
- enumerable: true,
23
- get: function () { return LogtoClient.Prompt; }
24
- });
25
- Object.defineProperty(exports, 'ReservedScope', {
26
- enumerable: true,
27
- get: function () { return LogtoClient.ReservedScope; }
28
- });
29
- Object.defineProperty(exports, 'UserScope', {
30
- enumerable: true,
31
- get: function () { return LogtoClient.UserScope; }
32
- });
33
- exports.LogtoProvider = provider.LogtoProvider;
34
- exports.useHandleSignInCallback = index.useHandleSignInCallback;
35
- exports.useLogto = index.useLogto;
1
+ export { LogtoClientError, LogtoError, OidcError, Prompt, ReservedScope, UserScope } from '@logto/browser';
2
+ export { LogtoProvider } from './provider.js';
3
+ export { useHandleSignInCallback, useLogto } from './hooks/index.js';
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var LogtoClient = require('@logto/browser');
5
+ var react = require('react');
6
+ var context = require('./context.cjs');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var LogtoClient__default = /*#__PURE__*/_interopDefault(LogtoClient);
11
+
12
+ const LogtoProvider = ({ config, children }) => {
13
+ const [loadingCount, setLoadingCount] = react.useState(1);
14
+ const memorizedLogtoClient = react.useMemo(() => ({ logtoClient: new LogtoClient__default.default(config) }), [config]);
15
+ const [isAuthenticated, setIsAuthenticated] = react.useState(false);
16
+ const [error, setError] = react.useState();
17
+ react.useEffect(() => {
18
+ (async () => {
19
+ const isAuthenticated = await memorizedLogtoClient.logtoClient.isAuthenticated();
20
+ setIsAuthenticated(isAuthenticated);
21
+ setLoadingCount((count) => Math.max(0, count - 1));
22
+ })();
23
+ }, [memorizedLogtoClient]);
24
+ const memorizedContextValue = react.useMemo(() => ({
25
+ ...memorizedLogtoClient,
26
+ isAuthenticated,
27
+ setIsAuthenticated,
28
+ loadingCount,
29
+ setLoadingCount,
30
+ error,
31
+ setError,
32
+ }), [memorizedLogtoClient, isAuthenticated, loadingCount, error]);
33
+ return jsxRuntime.jsx(context.LogtoContext.Provider, { value: memorizedContextValue, children: children });
34
+ };
35
+
36
+ exports.LogtoProvider = LogtoProvider;
package/lib/provider.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { LogtoConfig } from '@logto/browser';
2
- import { ReactNode } from 'react';
1
+ import { type LogtoConfig } from '@logto/browser';
2
+ import { type ReactNode } from 'react';
3
3
  export type LogtoProviderProps = {
4
4
  config: LogtoConfig;
5
5
  children?: ReactNode;
package/lib/provider.js CHANGED
@@ -1,27 +1,21 @@
1
- 'use strict';
2
-
3
- var jsxRuntime = require('react/jsx-runtime');
4
- var LogtoClient = require('@logto/browser');
5
- var react = require('react');
6
- var context = require('./context.js');
7
-
8
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
-
10
- var LogtoClient__default = /*#__PURE__*/_interopDefault(LogtoClient);
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import LogtoClient from '@logto/browser';
3
+ import { useState, useMemo, useEffect } from 'react';
4
+ import { LogtoContext } from './context.js';
11
5
 
12
6
  const LogtoProvider = ({ config, children }) => {
13
- const [loadingCount, setLoadingCount] = react.useState(1);
14
- const memorizedLogtoClient = react.useMemo(() => ({ logtoClient: new LogtoClient__default.default(config) }), [config]);
15
- const [isAuthenticated, setIsAuthenticated] = react.useState(false);
16
- const [error, setError] = react.useState();
17
- react.useEffect(() => {
7
+ const [loadingCount, setLoadingCount] = useState(1);
8
+ const memorizedLogtoClient = useMemo(() => ({ logtoClient: new LogtoClient(config) }), [config]);
9
+ const [isAuthenticated, setIsAuthenticated] = useState(false);
10
+ const [error, setError] = useState();
11
+ useEffect(() => {
18
12
  (async () => {
19
13
  const isAuthenticated = await memorizedLogtoClient.logtoClient.isAuthenticated();
20
14
  setIsAuthenticated(isAuthenticated);
21
15
  setLoadingCount((count) => Math.max(0, count - 1));
22
16
  })();
23
17
  }, [memorizedLogtoClient]);
24
- const memorizedContextValue = react.useMemo(() => ({
18
+ const memorizedContextValue = useMemo(() => ({
25
19
  ...memorizedLogtoClient,
26
20
  isAuthenticated,
27
21
  setIsAuthenticated,
@@ -30,7 +24,7 @@ const LogtoProvider = ({ config, children }) => {
30
24
  error,
31
25
  setError,
32
26
  }), [memorizedLogtoClient, isAuthenticated, loadingCount, error]);
33
- return jsxRuntime.jsx(context.LogtoContext.Provider, { value: memorizedContextValue, children: children });
27
+ return jsx(LogtoContext.Provider, { value: memorizedContextValue, children: children });
34
28
  };
35
29
 
36
- exports.LogtoProvider = LogtoProvider;
30
+ export { LogtoProvider };
package/package.json CHANGED
@@ -1,14 +1,16 @@
1
1
  {
2
2
  "name": "@logto/react",
3
- "version": "1.1.2",
4
- "source": "./src/index.ts",
5
- "main": "./lib/index.js",
3
+ "version": "2.0.1",
4
+ "type": "module",
5
+ "main": "./lib/index.cjs",
6
+ "module": "./lib/index.js",
7
+ "types": "./lib/index.d.ts",
6
8
  "exports": {
7
- "require": "./lib/index.js",
8
- "import": "./lib/index.mjs"
9
+ "types": "./lib/index.d.ts",
10
+ "require": "./lib/index.cjs",
11
+ "import": "./lib/index.js",
12
+ "default": "./lib/index.js"
9
13
  },
10
- "module": "./lib/index.mjs",
11
- "types": "./lib/index.d.ts",
12
14
  "files": [
13
15
  "lib"
14
16
  ],
@@ -18,37 +20,26 @@
18
20
  "url": "https://github.com/logto-io/js.git",
19
21
  "directory": "packages/react"
20
22
  },
21
- "scripts": {
22
- "dev:tsc": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
23
- "precommit": "lint-staged",
24
- "check": "tsc --noEmit",
25
- "build": "rm -rf lib/ && tsc -p tsconfig.build.json --noEmit && rollup -c",
26
- "lint": "eslint --ext .ts --ext .tsx src",
27
- "test": "jest",
28
- "test:coverage": "jest --silent --coverage",
29
- "prepack": "pnpm test"
30
- },
31
23
  "dependencies": {
32
- "@logto/browser": "^1.1.2",
33
- "@silverhand/essentials": "^2.6.1"
24
+ "@logto/browser": "^2.0.0",
25
+ "@silverhand/essentials": "^2.6.2"
34
26
  },
35
27
  "devDependencies": {
36
- "@jest/types": "^29.5.0",
37
- "@silverhand/eslint-config": "^2.0.0",
38
- "@silverhand/eslint-config-react": "^1.0.0",
39
- "@silverhand/ts-config": "^1.0.0",
40
- "@silverhand/ts-config-react": "^2.0.0",
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",
41
32
  "@swc/core": "^1.3.50",
42
33
  "@swc/jest": "^0.2.24",
43
- "@testing-library/react-hooks": "^8.0.0",
34
+ "@testing-library/react": "^14.0.0",
44
35
  "@types/jest": "^29.5.0",
45
- "@types/react": "^17.0.39",
36
+ "@types/react": "^18.2.0",
46
37
  "eslint": "^8.38.0",
47
38
  "jest": "^29.5.0",
48
39
  "lint-staged": "^13.0.0",
49
40
  "postcss": "^8.4.6",
50
41
  "prettier": "^2.8.7",
51
- "react": "^17.0.2",
42
+ "react": "^18.0.2",
52
43
  "stylelint": "^15.0.0",
53
44
  "typescript": "^5.0.0"
54
45
  },
@@ -62,5 +53,13 @@
62
53
  "publishConfig": {
63
54
  "access": "public"
64
55
  },
65
- "gitHead": "9e9a8b0887ef67baa7c3c564590bb06e7801d03e"
66
- }
56
+ "scripts": {
57
+ "dev:tsc": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
58
+ "precommit": "lint-staged",
59
+ "check": "tsc --noEmit",
60
+ "build": "rm -rf lib/ && tsc -p tsconfig.build.json --noEmit && rollup -c",
61
+ "lint": "eslint --ext .ts --ext .tsx src",
62
+ "test": "jest",
63
+ "test:coverage": "jest --silent --coverage"
64
+ }
65
+ }
package/lib/index.mjs DELETED
@@ -1,3 +0,0 @@
1
- export { LogtoClientError, LogtoError, OidcError, Prompt, ReservedScope, UserScope } from '@logto/browser';
2
- export { LogtoProvider } from './provider.mjs';
3
- export { useHandleSignInCallback, useLogto } from './hooks/index.mjs';
package/lib/provider.mjs DELETED
@@ -1,30 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import LogtoClient from '@logto/browser';
3
- import { useState, useMemo, useEffect } from 'react';
4
- import { LogtoContext } from './context.mjs';
5
-
6
- const LogtoProvider = ({ config, children }) => {
7
- const [loadingCount, setLoadingCount] = useState(1);
8
- const memorizedLogtoClient = useMemo(() => ({ logtoClient: new LogtoClient(config) }), [config]);
9
- const [isAuthenticated, setIsAuthenticated] = useState(false);
10
- const [error, setError] = useState();
11
- useEffect(() => {
12
- (async () => {
13
- const isAuthenticated = await memorizedLogtoClient.logtoClient.isAuthenticated();
14
- setIsAuthenticated(isAuthenticated);
15
- setLoadingCount((count) => Math.max(0, count - 1));
16
- })();
17
- }, [memorizedLogtoClient]);
18
- const memorizedContextValue = useMemo(() => ({
19
- ...memorizedLogtoClient,
20
- isAuthenticated,
21
- setIsAuthenticated,
22
- loadingCount,
23
- setLoadingCount,
24
- error,
25
- setError,
26
- }), [memorizedLogtoClient, isAuthenticated, loadingCount, error]);
27
- return jsx(LogtoContext.Provider, { value: memorizedContextValue, children: children });
28
- };
29
-
30
- export { LogtoProvider };