@asgardeo/auth-react 1.1.15 → 1.1.18
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticate.d.ts","sourceRoot":"","sources":["../../src/authenticate.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAEH,iBAAiB,EAQpB,MAAM,oBAAoB,CAAC;AAE5B,OAAc,EACV,iBAAiB,
|
|
1
|
+
{"version":3,"file":"authenticate.d.ts","sourceRoot":"","sources":["../../src/authenticate.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAEH,iBAAiB,EAQpB,MAAM,oBAAoB,CAAC;AAE5B,OAAc,EACV,iBAAiB,EAEjB,iBAAiB,EACjB,SAAS,EAOZ,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,UAAU,EAAe,MAAM,GAAG,CAAC;AAE5C,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAsB,MAAM,UAAU,CAAC;AAcrF,UAAU,0BAA0B;IAChC,MAAM,EAAE,eAAe,CAAC;IACxB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;IAC1C,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,MAAM,CAAC,EAAE,iBAAiB,CAAC;CAC9B;AAED,QAAA,MAAM,YAAY,EAAE,iBAAiB,CAAC,iBAAiB,CAAC,0BAA0B,CAAC,CA+MlF,CAAC;AAEF,QAAA,MAAM,cAAc,QAAO,oBAE1B,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secure-route.d.ts","sourceRoot":"","sources":["../../src/secure-route.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAc,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"secure-route.d.ts","sourceRoot":"","sources":["../../src/secure-route.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAc,EAAE,iBAAiB,EAAqD,MAAM,OAAO,CAAC;AACpG,OAAO,EAAS,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAEhD;;;;;;GAMG;AACH,QAAA,MAAM,WAAW,EAAE,iBAAiB,CAAC,oBAAoB,GAAG,UAAU,CAsCrE,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -596,7 +596,7 @@
|
|
|
596
596
|
"affectsGlobalScope": false
|
|
597
597
|
},
|
|
598
598
|
"../src/secure-route.tsx": {
|
|
599
|
-
"version": "
|
|
599
|
+
"version": "1adc1b9bb0a3c981da175e3584852e714f2acc9ab987f9158a700e12342eca55",
|
|
600
600
|
"signature": "a7444f6cda6b9d661a122ba8530dc1941173ae0ab22e75d7adca56b6b99bd40c",
|
|
601
601
|
"affectsGlobalScope": false
|
|
602
602
|
},
|
|
@@ -621,7 +621,7 @@
|
|
|
621
621
|
"affectsGlobalScope": false
|
|
622
622
|
},
|
|
623
623
|
"../src/authenticate.tsx": {
|
|
624
|
-
"version": "
|
|
624
|
+
"version": "7b80cd0e2b843d12ad19d3c473efa3d95c4ce9854e6ff71dc71e7d131a3824b1",
|
|
625
625
|
"signature": "150d2de23192873482689c0b27ce8d8aa18d83441455f5402821f15f64b59133",
|
|
626
626
|
"affectsGlobalScope": false
|
|
627
627
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asgardeo/auth-react",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.18",
|
|
4
4
|
"description": "Asgardeo Auth React SDK for React Applications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"WSO2",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"fix-lint": "eslint --ext .js,.ts . --fix",
|
|
23
23
|
"build": "rimraf dist && npm run type-check && webpack -p --env.NODE_ENV=production",
|
|
24
24
|
"build:dev": "rimraf dist && npm run type-check && webpack -p --env.NODE_ENV=development",
|
|
25
|
+
"build:watch": "npm run build:dev -- --watch",
|
|
25
26
|
"type-check": "tsc --emitDeclarationOnly",
|
|
26
27
|
"type-check:watch": "npm run type-check -- --watch"
|
|
27
28
|
},
|
|
@@ -36,7 +37,7 @@
|
|
|
36
37
|
"author": "WSO2",
|
|
37
38
|
"license": "Apache-2.0",
|
|
38
39
|
"dependencies": {
|
|
39
|
-
"@asgardeo/auth-spa": "^0.4.
|
|
40
|
+
"@asgardeo/auth-spa": "^0.4.8"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
43
|
"@babel/cli": "^7.10.5",
|
package/src/authenticate.tsx
CHANGED
|
@@ -30,12 +30,14 @@ import {
|
|
|
30
30
|
import { SPACustomGrantConfig } from "@asgardeo/auth-spa/src/models/request-custom-grant";
|
|
31
31
|
import React, {
|
|
32
32
|
FunctionComponent,
|
|
33
|
+
MutableRefObject,
|
|
33
34
|
PropsWithChildren,
|
|
34
35
|
ReactNode,
|
|
35
36
|
createContext,
|
|
36
37
|
useContext,
|
|
37
38
|
useEffect,
|
|
38
39
|
useMemo,
|
|
40
|
+
useRef,
|
|
39
41
|
useState
|
|
40
42
|
} from "react";
|
|
41
43
|
import { AuthParams, ReactConfig } from ".";
|
|
@@ -131,6 +133,7 @@ const AuthProvider: FunctionComponent<PropsWithChildren<AuthProviderPropsInterfa
|
|
|
131
133
|
const trySignInSilently = () => AuthClient.trySignInSilently(state, dispatch);
|
|
132
134
|
|
|
133
135
|
const [ error, setError ] = useState<AsgardeoAuthException>();
|
|
136
|
+
const reRenderCheckRef: MutableRefObject<boolean> = useRef(false);
|
|
134
137
|
|
|
135
138
|
useEffect(() => {
|
|
136
139
|
if (state.isAuthenticated) {
|
|
@@ -146,6 +149,18 @@ const AuthProvider: FunctionComponent<PropsWithChildren<AuthProviderPropsInterfa
|
|
|
146
149
|
* Try signing in when the component is mounted.
|
|
147
150
|
*/
|
|
148
151
|
useEffect(() => {
|
|
152
|
+
// React 18.x Strict.Mode has a new check for `Ensuring reusable state` to facilitate an upcoming react feature.
|
|
153
|
+
// https://reactjs.org/docs/strict-mode.html#ensuring-reusable-state
|
|
154
|
+
// This will remount all the useEffects to ensure that there are no unexpected side effects.
|
|
155
|
+
// When react remounts the signIn hook of the AuthProvider, it will cause a race condition. Hence, we have to
|
|
156
|
+
// prevent the re-render of this hook as suggested in the following discussion.
|
|
157
|
+
// https://github.com/reactwg/react-18/discussions/18#discussioncomment-795623
|
|
158
|
+
if (reRenderCheckRef.current) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
reRenderCheckRef.current = true;
|
|
163
|
+
|
|
149
164
|
(async () => {
|
|
150
165
|
let isSignedOut: boolean = false;
|
|
151
166
|
// If the component was mounted after the user was redirected to the application upon a successful logout,
|
package/src/secure-route.tsx
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* under the License.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import React, { FunctionComponent, ReactElement, useEffect } from "react";
|
|
19
|
+
import React, { FunctionComponent, MutableRefObject, ReactElement, useEffect, useRef } from "react";
|
|
20
20
|
import { Route, RouteProps } from "react-router-dom";
|
|
21
21
|
import { useAuthContext } from "./authenticate";
|
|
22
22
|
import { SecureRouteInterface } from "./models";
|
|
@@ -31,15 +31,28 @@ import { SecureRouteInterface } from "./models";
|
|
|
31
31
|
const SecureRoute: FunctionComponent<SecureRouteInterface & RouteProps> = (props: SecureRouteInterface & RouteProps
|
|
32
32
|
): ReactElement => {
|
|
33
33
|
const { state } = useAuthContext();
|
|
34
|
+
const reRenderCheckRef: MutableRefObject<boolean> = useRef(false);
|
|
34
35
|
|
|
35
36
|
const { component: Component, callback, ...rest } = props;
|
|
36
37
|
|
|
37
38
|
useEffect(() => {
|
|
38
|
-
if (
|
|
39
|
-
|
|
39
|
+
if (state.isAuthenticated || state.isLoading) {
|
|
40
|
+
return;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
|
|
43
|
+
// React 18.x Strict.Mode has a new check for `Ensuring reusable state` to facilitate an upcoming react feature.
|
|
44
|
+
// https://reactjs.org/docs/strict-mode.html#ensuring-reusable-state
|
|
45
|
+
// This will remount all the useEffects to ensure that there are no unexpected side effects.
|
|
46
|
+
// When react remounts the signIn hook of the AuthProvider, it will cause a race condition. Hence, we have to
|
|
47
|
+
// prevent the re-render of this hook as suggested in the following discussion.
|
|
48
|
+
// https://github.com/reactwg/react-18/discussions/18#discussioncomment-795623
|
|
49
|
+
if (reRenderCheckRef.current) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
reRenderCheckRef.current = true;
|
|
54
|
+
callback && callback();
|
|
55
|
+
}, [ state.isAuthenticated, state.isLoading ]);
|
|
43
56
|
|
|
44
57
|
if (!state.isAuthenticated) {
|
|
45
58
|
return null;
|