oidc-jwt-client
Advanced tools
Comparing version 2.1.0-develop.2 to 2.1.0
@@ -840,29 +840,24 @@ import React, { useReducer, useRef, useEffect, useLayoutEffect, useContext, useCallback, useState } from 'react'; | ||
}, | ||
loadInitialData: function () { | ||
var _a = get().methods, receiveSessionToken = _a.receiveSessionToken, getAccessToken = _a.getAccessToken, getInitialUserInfo = _a.getInitialUserInfo, setInitializedData = _a.setInitializedData; | ||
loadInitialData: function (redirect) { | ||
if (redirect === void 0) { redirect = true; } | ||
var _a = get().methods, receiveSessionToken = _a.receiveSessionToken, getAccessToken = _a.getAccessToken, getUserInfo = _a.getUserInfo, removeTokenFromUrl = _a.removeTokenFromUrl, setInitializedData = _a.setInitializedData; | ||
var token = receiveSessionToken(); | ||
return getInitialUserInfo(token, true).then(function () { return getAccessToken().then(function (info) { | ||
var _a; | ||
setInitializedData((_a = info === null || info === void 0 ? void 0 : info.claims) !== null && _a !== void 0 ? _a : null); | ||
}); }); | ||
return getUserInfo().then(function (data) { | ||
if (!data || !token) { | ||
setInitializedData(null); | ||
return; | ||
} | ||
if (redirect) { | ||
removeTokenFromUrl(); | ||
} | ||
return getAccessToken().then(function (info) { | ||
var _a; | ||
setInitializedData((_a = info === null || info === void 0 ? void 0 : info.claims) !== null && _a !== void 0 ? _a : null); | ||
}); | ||
}); | ||
}, | ||
removeTokenFromUrl: function (data, redirect) { | ||
if (redirect === void 0) { redirect = true; } | ||
if (redirect) { | ||
var urlWithoutToken = stripTokenFromUrl(window.location.href).replace(/\?$/, '').replace(/#\.$/, ''); | ||
window.history.replaceState({}, '', urlWithoutToken); | ||
return data; | ||
} | ||
return null; | ||
removeTokenFromUrl: function () { | ||
var urlWithoutToken = stripTokenFromUrl(window.location.href).replace(/\?$/, '').replace(/#\.$/, ''); | ||
window.history.replaceState({}, '', urlWithoutToken); | ||
}, | ||
getInitialUserInfo: function (token, redirect) { | ||
if (redirect === void 0) { redirect = true; } | ||
var _a = get().methods, getUserInfo = _a.getUserInfo, removeTokenFromUrl = _a.removeTokenFromUrl; | ||
var getUserInfoPromise = getUserInfo(); | ||
if (!token) | ||
return getUserInfoPromise; | ||
return getUserInfoPromise | ||
.then(function (data) { return removeTokenFromUrl(data, redirect); }) | ||
.catch(function (data) { return removeTokenFromUrl(data, redirect); }); | ||
}, | ||
receiveSessionToken: function () { | ||
@@ -869,0 +864,0 @@ var setSessionToken = get().methods.setSessionToken; |
@@ -848,29 +848,24 @@ 'use strict'; | ||
}, | ||
loadInitialData: function () { | ||
var _a = get().methods, receiveSessionToken = _a.receiveSessionToken, getAccessToken = _a.getAccessToken, getInitialUserInfo = _a.getInitialUserInfo, setInitializedData = _a.setInitializedData; | ||
loadInitialData: function (redirect) { | ||
if (redirect === void 0) { redirect = true; } | ||
var _a = get().methods, receiveSessionToken = _a.receiveSessionToken, getAccessToken = _a.getAccessToken, getUserInfo = _a.getUserInfo, removeTokenFromUrl = _a.removeTokenFromUrl, setInitializedData = _a.setInitializedData; | ||
var token = receiveSessionToken(); | ||
return getInitialUserInfo(token, true).then(function () { return getAccessToken().then(function (info) { | ||
var _a; | ||
setInitializedData((_a = info === null || info === void 0 ? void 0 : info.claims) !== null && _a !== void 0 ? _a : null); | ||
}); }); | ||
return getUserInfo().then(function (data) { | ||
if (!data || !token) { | ||
setInitializedData(null); | ||
return; | ||
} | ||
if (redirect) { | ||
removeTokenFromUrl(); | ||
} | ||
return getAccessToken().then(function (info) { | ||
var _a; | ||
setInitializedData((_a = info === null || info === void 0 ? void 0 : info.claims) !== null && _a !== void 0 ? _a : null); | ||
}); | ||
}); | ||
}, | ||
removeTokenFromUrl: function (data, redirect) { | ||
if (redirect === void 0) { redirect = true; } | ||
if (redirect) { | ||
var urlWithoutToken = stripTokenFromUrl(window.location.href).replace(/\?$/, '').replace(/#\.$/, ''); | ||
window.history.replaceState({}, '', urlWithoutToken); | ||
return data; | ||
} | ||
return null; | ||
removeTokenFromUrl: function () { | ||
var urlWithoutToken = stripTokenFromUrl(window.location.href).replace(/\?$/, '').replace(/#\.$/, ''); | ||
window.history.replaceState({}, '', urlWithoutToken); | ||
}, | ||
getInitialUserInfo: function (token, redirect) { | ||
if (redirect === void 0) { redirect = true; } | ||
var _a = get().methods, getUserInfo = _a.getUserInfo, removeTokenFromUrl = _a.removeTokenFromUrl; | ||
var getUserInfoPromise = getUserInfo(); | ||
if (!token) | ||
return getUserInfoPromise; | ||
return getUserInfoPromise | ||
.then(function (data) { return removeTokenFromUrl(data, redirect); }) | ||
.catch(function (data) { return removeTokenFromUrl(data, redirect); }); | ||
}, | ||
receiveSessionToken: function () { | ||
@@ -877,0 +872,0 @@ var setSessionToken = get().methods.setSessionToken; |
@@ -26,17 +26,10 @@ import { UseStore } from 'zustand'; | ||
* Receive session token and return user info | ||
* @returns Promise<Claims | User | null> | ||
*/ | ||
loadInitialData<Claims extends ClaimsBase, User>(): Promise<void>; | ||
/** | ||
* Try to remove token from url if redirect is true | ||
* @param redirect If true (the default), redirect to the same page without the token. | ||
* @returns User | null | ||
* @returns Promise<void> | ||
*/ | ||
removeTokenFromUrl<User>(data: User | null, redirect?: boolean): User | null; | ||
loadInitialData<Claims extends ClaimsBase, User>(redirect?: boolean): Promise<void>; | ||
/** | ||
* Get initial user info promise | ||
* @param redirect If true (the default), redirect to the same page without the token. | ||
* @returns Promise<User | null> | ||
* Try to remove token from url | ||
*/ | ||
getInitialUserInfo<User>(token: string | null, redirect?: boolean): Promise<User | null>; | ||
removeTokenFromUrl(): void; | ||
/** | ||
@@ -43,0 +36,0 @@ * Read the session token from the URL. Remove it from the URL if possible. |
{ | ||
"name": "oidc-jwt-client", | ||
"version": "2.1.0-develop.2", | ||
"version": "2.1.0", | ||
"description": "Fetch JWTs for API access from oidc-jwt-provider", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
240716
2164