oidc-jwt-client
Advanced tools
Comparing version 4.0.18-develop.5 to 4.0.18-develop.6
@@ -25,18 +25,20 @@ 'use strict'; | ||
var OidcJwtInitializer = function (_a) { | ||
var _b = _a.shouldAttemptLogin, shouldAttemptLogin = _b === void 0 ? false : _b, _c = _a.shouldMonitorAccessTokens, shouldMonitorAccessTokens = _c === void 0 ? true : _c, children = _a.children; | ||
var _b = _a.shouldAttemptLogin, shouldAttemptLogin = _b === void 0 ? false : _b, _c = _a.shouldMonitorAccessTokens, shouldMonitorAccessTokens = _c === void 0 ? true : _c, _d = _a.isMounted, isMounted = _d === void 0 ? false : _d, children = _a.children; | ||
var authService = useOidcJwtStore(function (state) { return state.service; }); | ||
var isLoggedIn = useOidcJwtStore(function (state) { return state.authState.isLoggedIn; }); | ||
var setState = useOidcJwtStore(function (state) { return state.setState; }); | ||
var _d = React.useState(false), isInitializing = _d[0], setIsInitializing = _d[1]; | ||
var _e = React.useState(false), isInitializing = _e[0], setIsInitializing = _e[1]; | ||
React.useEffect(function () { | ||
if (!isMounted) | ||
return; | ||
authService === null || authService === void 0 ? void 0 : authService.loadInitialData().then(function () { return setState(authService.state); }); | ||
}, [authService, setState]); | ||
}, [authService, isMounted, setState]); | ||
React.useEffect(function () { | ||
if (!isLoggedIn || !shouldMonitorAccessTokens) | ||
if (!isLoggedIn || !shouldMonitorAccessTokens || !isMounted) | ||
return; | ||
authService === null || authService === void 0 ? void 0 : authService.monitorAccessToken(function () { return setState(authService.state); }); | ||
return function () { return authService === null || authService === void 0 ? void 0 : authService.stopMonitoringAccessToken(); }; | ||
}, [isLoggedIn, authService, shouldMonitorAccessTokens, setState]); | ||
}, [isLoggedIn, authService, shouldMonitorAccessTokens, setState, isMounted]); | ||
React.useEffect(function () { | ||
if (!authService) | ||
if (!authService || !isMounted) | ||
return; | ||
@@ -47,3 +49,3 @@ var csrfToken = authService.getCsrfToken().csrfToken; | ||
authService.authorize({ prompt: 'none' }); | ||
}, [authService, isLoggedIn, shouldAttemptLogin]); | ||
}, [authService, isLoggedIn, isMounted, shouldAttemptLogin]); | ||
React.useEffect(function () { | ||
@@ -60,2 +62,3 @@ var isInitializing = !(authService === null || authService === void 0 ? void 0 : authService.getCsrfToken().csrfToken) && shouldAttemptLogin && !isLoggedIn; | ||
var client = props.client, _a = props.removeTokenFromUrlFunction, removeTokenFromUrlFunction = _a === void 0 ? stripTokenFromUrl.removeTokenFromUrl : _a, children = props.children; | ||
var _b = React.useState(false), isMounted = _b[0], setMounted = _b[1]; | ||
var store$1 = React.useRef(store.createOidcJwtClientStore(client, removeTokenFromUrlFunction)).current; | ||
@@ -67,9 +70,10 @@ React.useEffect(function () { | ||
isLoggedIn: !!storage.Storage.get(constants.LOGGED_IN_TOKEN_STORAGE_KEY), | ||
isInitialized: !client, | ||
isInitialized: false, | ||
didRetryLogin: storage.Storage.get(constants.RETRY_LOGIN_STORAGE_KEY) === 1, | ||
}; | ||
setMounted(true); | ||
store$1.setState({ authState: initialState }); | ||
}, [client, store$1]); | ||
return (React__default.default.createElement(OidcJwtContext.Provider, { value: store$1 }, | ||
React__default.default.createElement(OidcJwtInitializer, tslib_es6.__assign({}, props), children))); | ||
React__default.default.createElement(OidcJwtInitializer, tslib_es6.__assign({ isMounted: isMounted }, props), children))); | ||
}; | ||
@@ -76,0 +80,0 @@ |
import { __assign } from './node_modules/tslib/tslib.es6.js'; | ||
import React, { createContext, useContext, useRef, useEffect, useState } from 'react'; | ||
import React, { createContext, useContext, useState, useRef, useEffect } from 'react'; | ||
import { useStore } from 'zustand'; | ||
@@ -19,18 +19,20 @@ import { USER_INFO_TOKEN_STORAGE_KEY, CSRF_TOKEN_STORAGE_KEY, LOGGED_IN_TOKEN_STORAGE_KEY, RETRY_LOGIN_STORAGE_KEY } from './constants.js'; | ||
var OidcJwtInitializer = function (_a) { | ||
var _b = _a.shouldAttemptLogin, shouldAttemptLogin = _b === void 0 ? false : _b, _c = _a.shouldMonitorAccessTokens, shouldMonitorAccessTokens = _c === void 0 ? true : _c, children = _a.children; | ||
var _b = _a.shouldAttemptLogin, shouldAttemptLogin = _b === void 0 ? false : _b, _c = _a.shouldMonitorAccessTokens, shouldMonitorAccessTokens = _c === void 0 ? true : _c, _d = _a.isMounted, isMounted = _d === void 0 ? false : _d, children = _a.children; | ||
var authService = useOidcJwtStore(function (state) { return state.service; }); | ||
var isLoggedIn = useOidcJwtStore(function (state) { return state.authState.isLoggedIn; }); | ||
var setState = useOidcJwtStore(function (state) { return state.setState; }); | ||
var _d = useState(false), isInitializing = _d[0], setIsInitializing = _d[1]; | ||
var _e = useState(false), isInitializing = _e[0], setIsInitializing = _e[1]; | ||
useEffect(function () { | ||
if (!isMounted) | ||
return; | ||
authService === null || authService === void 0 ? void 0 : authService.loadInitialData().then(function () { return setState(authService.state); }); | ||
}, [authService, setState]); | ||
}, [authService, isMounted, setState]); | ||
useEffect(function () { | ||
if (!isLoggedIn || !shouldMonitorAccessTokens) | ||
if (!isLoggedIn || !shouldMonitorAccessTokens || !isMounted) | ||
return; | ||
authService === null || authService === void 0 ? void 0 : authService.monitorAccessToken(function () { return setState(authService.state); }); | ||
return function () { return authService === null || authService === void 0 ? void 0 : authService.stopMonitoringAccessToken(); }; | ||
}, [isLoggedIn, authService, shouldMonitorAccessTokens, setState]); | ||
}, [isLoggedIn, authService, shouldMonitorAccessTokens, setState, isMounted]); | ||
useEffect(function () { | ||
if (!authService) | ||
if (!authService || !isMounted) | ||
return; | ||
@@ -41,3 +43,3 @@ var csrfToken = authService.getCsrfToken().csrfToken; | ||
authService.authorize({ prompt: 'none' }); | ||
}, [authService, isLoggedIn, shouldAttemptLogin]); | ||
}, [authService, isLoggedIn, isMounted, shouldAttemptLogin]); | ||
useEffect(function () { | ||
@@ -54,2 +56,3 @@ var isInitializing = !(authService === null || authService === void 0 ? void 0 : authService.getCsrfToken().csrfToken) && shouldAttemptLogin && !isLoggedIn; | ||
var client = props.client, _a = props.removeTokenFromUrlFunction, removeTokenFromUrlFunction = _a === void 0 ? removeTokenFromUrl : _a, children = props.children; | ||
var _b = useState(false), isMounted = _b[0], setMounted = _b[1]; | ||
var store = useRef(createOidcJwtClientStore(client, removeTokenFromUrlFunction)).current; | ||
@@ -61,9 +64,10 @@ useEffect(function () { | ||
isLoggedIn: !!Storage.get(LOGGED_IN_TOKEN_STORAGE_KEY), | ||
isInitialized: !client, | ||
isInitialized: false, | ||
didRetryLogin: Storage.get(RETRY_LOGIN_STORAGE_KEY) === 1, | ||
}; | ||
setMounted(true); | ||
store.setState({ authState: initialState }); | ||
}, [client, store]); | ||
return (React.createElement(OidcJwtContext.Provider, { value: store }, | ||
React.createElement(OidcJwtInitializer, __assign({}, props), children))); | ||
React.createElement(OidcJwtInitializer, __assign({ isMounted: isMounted }, props), children))); | ||
}; | ||
@@ -70,0 +74,0 @@ |
{ | ||
"name": "oidc-jwt-client", | ||
"version": "4.0.18-develop.5", | ||
"version": "4.0.18-develop.6", | ||
"description": "Fetch JWTs for API access from oidc-jwt-provider", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
172582
1655