@conduit-d365/auth 0.2.0 → 0.2.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/dist/ProtectedRoute.d.ts
CHANGED
|
@@ -8,8 +8,8 @@ interface ProtectedRouteProps {
|
|
|
8
8
|
* Route guard that requires authentication.
|
|
9
9
|
*
|
|
10
10
|
* While MSAL is initialising, shows a loading indicator. If the user
|
|
11
|
-
* is not authenticated, triggers a login redirect
|
|
12
|
-
* the children.
|
|
11
|
+
* is not authenticated, triggers a login redirect (once only per mount).
|
|
12
|
+
* Otherwise renders the children.
|
|
13
13
|
*
|
|
14
14
|
* Usage:
|
|
15
15
|
* <Route path="/projects" element={
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProtectedRoute.d.ts","sourceRoot":"","sources":["../src/ProtectedRoute.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ProtectedRoute.d.ts","sourceRoot":"","sources":["../src/ProtectedRoute.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAiB,MAAM,OAAO,CAAC;AAGtC,UAAU,mBAAmB;IAC3B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,uEAAuE;IACvE,gBAAgB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CACpC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,gBAAgB,GACjB,EAAE,mBAAmB,2CAiBrB"}
|
package/dist/ProtectedRoute.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useRef } from "react";
|
|
2
3
|
import { useAuth } from "./useAuth";
|
|
3
4
|
/**
|
|
4
5
|
* Route guard that requires authentication.
|
|
5
6
|
*
|
|
6
7
|
* While MSAL is initialising, shows a loading indicator. If the user
|
|
7
|
-
* is not authenticated, triggers a login redirect
|
|
8
|
-
* the children.
|
|
8
|
+
* is not authenticated, triggers a login redirect (once only per mount).
|
|
9
|
+
* Otherwise renders the children.
|
|
9
10
|
*
|
|
10
11
|
* Usage:
|
|
11
12
|
* <Route path="/projects" element={
|
|
@@ -16,11 +17,15 @@ import { useAuth } from "./useAuth";
|
|
|
16
17
|
*/
|
|
17
18
|
export function ProtectedRoute({ children, loadingComponent, }) {
|
|
18
19
|
const { isAuthenticated, isLoading, login } = useAuth();
|
|
20
|
+
const loginTriggered = useRef(false);
|
|
19
21
|
if (isLoading) {
|
|
20
22
|
return _jsx(_Fragment, { children: loadingComponent ?? _jsx("div", { children: "Loading..." }) });
|
|
21
23
|
}
|
|
22
24
|
if (!isAuthenticated) {
|
|
23
|
-
|
|
25
|
+
if (!loginTriggered.current) {
|
|
26
|
+
loginTriggered.current = true;
|
|
27
|
+
login();
|
|
28
|
+
}
|
|
24
29
|
return _jsx("div", { children: "Redirecting to login..." });
|
|
25
30
|
}
|
|
26
31
|
return _jsx(_Fragment, { children: children });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProtectedRoute.js","sourceRoot":"","sources":["../src/ProtectedRoute.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"ProtectedRoute.js","sourceRoot":"","sources":["../src/ProtectedRoute.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,cAAc,CAAC,EAC7B,QAAQ,EACR,gBAAgB,GACI;IACpB,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC;IACxD,MAAM,cAAc,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAErC,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,4BAAG,gBAAgB,IAAI,uCAAqB,GAAI,CAAC;IAC1D,CAAC;IAED,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;YAC5B,cAAc,CAAC,OAAO,GAAG,IAAI,CAAC;YAC9B,KAAK,EAAE,CAAC;QACV,CAAC;QACD,OAAO,oDAAkC,CAAC;IAC5C,CAAC;IAED,OAAO,4BAAG,QAAQ,GAAI,CAAC;AACzB,CAAC"}
|