oidc-react
Advanced tools
Comparing version 3.0.1 to 3.0.2
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
@@ -125,6 +136,7 @@ if (k2 === undefined) k2 = k; | ||
var AuthProvider = function (_a) { | ||
var children = _a.children, _b = _a.autoSignIn, autoSignIn = _b === void 0 ? true : _b, onBeforeSignIn = _a.onBeforeSignIn, onSignIn = _a.onSignIn, onSignOut = _a.onSignOut, _c = _a.location, location = _c === void 0 ? window.location : _c, props = __rest(_a, ["children", "autoSignIn", "onBeforeSignIn", "onSignIn", "onSignOut", "location"]); | ||
var _d = (0, react_1.useState)(true), isLoading = _d[0], setIsLoading = _d[1]; | ||
var _e = (0, react_1.useState)(null), userData = _e[0], setUserData = _e[1]; | ||
var children = _a.children, _b = _a.autoSignIn, autoSignIn = _b === void 0 ? true : _b, autoSignInArgs = _a.autoSignInArgs, _c = _a.autoSignOut, autoSignOut = _c === void 0 ? true : _c, autoSignOutArgs = _a.autoSignOutArgs, onBeforeSignIn = _a.onBeforeSignIn, onSignIn = _a.onSignIn, onSignOut = _a.onSignOut, _d = _a.location, location = _d === void 0 ? window.location : _d, props = __rest(_a, ["children", "autoSignIn", "autoSignInArgs", "autoSignOut", "autoSignOutArgs", "onBeforeSignIn", "onSignIn", "onSignOut", "location"]); | ||
var _e = (0, react_1.useState)(true), isLoading = _e[0], setIsLoading = _e[1]; | ||
var _f = (0, react_1.useState)(null), userData = _f[0], setUserData = _f[1]; | ||
var userManager = (0, react_1.useState)(function () { return (0, exports.initUserManager)(props); })[0]; | ||
var isMountedRef = (0, react_1.useRef)(false); | ||
var signOutHooks = (0, react_1.useCallback)(function () { return __awaiter(void 0, void 0, void 0, function () { | ||
@@ -153,16 +165,9 @@ return __generator(this, function (_a) { | ||
}); }, [userManager, onSignIn]); | ||
var isMountedRef = (0, react_1.useRef)(true); | ||
(0, react_1.useEffect)(function () { | ||
return function () { | ||
isMountedRef.current = false; | ||
}; | ||
}, []); | ||
(0, react_1.useEffect)(function () { | ||
isMountedRef.current = true; | ||
(function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var isMounted, user, user_1, state; | ||
var user, user_1, state; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
isMounted = isMountedRef.current; | ||
return [4 /*yield*/, userManager.getUser()]; | ||
case 0: return [4 /*yield*/, userManager.getUser()]; | ||
case 1: | ||
@@ -179,24 +184,51 @@ user = _a.sent(); | ||
case 3: | ||
if ((!user || user.expired) && autoSignIn) { | ||
state = onBeforeSignIn ? onBeforeSignIn() : undefined; | ||
userManager.signinRedirect({ state: state }); | ||
} | ||
else if (isMounted) { | ||
if (!((!user || user.expired) && autoSignIn)) return [3 /*break*/, 5]; | ||
state = onBeforeSignIn ? onBeforeSignIn() : undefined; | ||
return [4 /*yield*/, userManager.signinRedirect(__assign(__assign({}, autoSignInArgs), { state: state }))]; | ||
case 4: | ||
_a.sent(); | ||
return [3 /*break*/, 6]; | ||
case 5: | ||
if (isMountedRef.current) { | ||
setUserData(user); | ||
setIsLoading(false); | ||
} | ||
return [2 /*return*/]; | ||
_a.label = 6; | ||
case 6: return [2 /*return*/]; | ||
} | ||
}); | ||
}); })(); | ||
return function () { | ||
isMountedRef.current = false; | ||
}; | ||
}, [location, userManager, autoSignIn, onBeforeSignIn, onSignIn]); | ||
/** | ||
* Registers a UserLoadedCallback to update the userData state on a userLoaded event | ||
* Registers UserManager event callbacks for handling changes to user state due to automaticSilentRenew, session expiry, etc. | ||
*/ | ||
(0, react_1.useEffect)(function () { | ||
var updateUserData = function (user) { | ||
isMountedRef.current && setUserData(user); | ||
setUserData(user); | ||
}; | ||
var onSilentRenewError = function (error) { return __awaiter(void 0, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!autoSignOut) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, signOutHooks()]; | ||
case 1: | ||
_a.sent(); | ||
return [4 /*yield*/, userManager.signoutRedirect(autoSignOutArgs)]; | ||
case 2: | ||
_a.sent(); | ||
_a.label = 3; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); }; | ||
userManager.events.addUserLoaded(updateUserData); | ||
return function () { return userManager.events.removeUserLoaded(updateUserData); }; | ||
userManager.events.addSilentRenewError(onSilentRenewError); | ||
return function () { | ||
userManager.events.removeUserLoaded(updateUserData); | ||
userManager.events.removeSilentRenewError(onSilentRenewError); | ||
}; | ||
}, [userManager]); | ||
@@ -203,0 +235,0 @@ var value = (0, react_1.useMemo)(function () { |
@@ -72,9 +72,25 @@ import { UserManager, User, PopupWindowFeatures, SigninRedirectArgs, SignoutRedirectArgs } from 'oidc-client-ts'; | ||
/** | ||
* defaults to true | ||
* Flag to control automatic redirection to the OIDC/OAuth2 provider when not signed in. | ||
* | ||
* Defaults to true. | ||
*/ | ||
autoSignIn?: boolean; | ||
/** | ||
* Optional sign in arguments to be used when `autoSignIn` is enabled. | ||
*/ | ||
autoSignInArgs?: SigninRedirectArgs; | ||
/** | ||
* Flag to control automatic sign out redirection to the OIDC/OAuth2 provider when silent renewal fails. | ||
* | ||
* Defaults to true. | ||
*/ | ||
autoSignOut?: boolean; | ||
/** | ||
* Optional sign out arguments to be used when `autoSignOut` is enabled. | ||
*/ | ||
autoSignOutArgs?: SignoutRedirectArgs; | ||
/** | ||
* Flag to indicate if there should be an automatic attempt to renew the access token prior to its expiration. | ||
* | ||
* defaults to false | ||
* Defaults to true. | ||
*/ | ||
@@ -85,3 +101,3 @@ automaticSilentRenew?: boolean; | ||
* | ||
* defaults to true | ||
* Defaults to true. | ||
*/ | ||
@@ -101,4 +117,3 @@ loadUserInfo?: boolean; | ||
/** | ||
* The target parameter to window.open for the popup signin window. | ||
* | ||
* The target parameter to window.open for the popup signin window. * | ||
* defaults to '_blank' | ||
@@ -110,4 +125,3 @@ */ | ||
* | ||
* This only gets called if autoSignIn is true | ||
*/ | ||
* This only gets called if autoSignIn is true */ | ||
onBeforeSignIn?: () => string; | ||
@@ -114,0 +128,0 @@ /** |
@@ -6,2 +6,9 @@ # Changelog | ||
## [3.0.2](https://github.com/bjerkio/oidc-react/compare/v3.0.1...v3.0.2) (2023-03-12) | ||
### Bug Fixes | ||
* handle token refresh failure ([#968](https://github.com/bjerkio/oidc-react/issues/968)) ([751732b](https://github.com/bjerkio/oidc-react/commit/751732b636b1911ff07bb86e34fff80ff5f39933)) | ||
## [3.0.1](https://github.com/bjerkio/oidc-react/compare/v3.0.0...v3.0.1) (2023-03-08) | ||
@@ -8,0 +15,0 @@ |
{ | ||
"name": "oidc-react", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"private": false, | ||
@@ -32,3 +32,3 @@ "description": "", | ||
"@types/jest": "29.4.0", | ||
"@types/node": "18.14.6", | ||
"@types/node": "18.15.0", | ||
"@types/react": "18.0.28", | ||
@@ -38,3 +38,3 @@ "@typescript-eslint/eslint-plugin": "5.54.1", | ||
"bundlewatch": "0.3.3", | ||
"eslint": "8.35.0", | ||
"eslint": "8.36.0", | ||
"eslint-config-airbnb-base": "15.0.0", | ||
@@ -41,0 +41,0 @@ "eslint-config-prettier": "8.7.0", |
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
49336
559