@jfront/oauth-user
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -6,2 +6,11 @@ # Change Log | ||
## [0.2.4](https://github.com/Jepria/jfront-oauth/compare/@jfront/oauth-user@0.2.3...@jfront/oauth-user@0.2.4) (2023-05-27) | ||
**Note:** Version bump only for package @jfront/oauth-user | ||
# Change Log | ||
All notable changes to this project will be documented in this file. See | ||
[Conventional Commits](https://conventionalcommits.org) for commit guidelines. | ||
## [0.2.3](https://github.com/Jepria/jfront-oauth/compare/@jfront/oauth-user@0.2.2...@jfront/oauth-user@0.2.3) (2022-12-30) | ||
@@ -8,0 +17,0 @@ |
@@ -79,2 +79,21 @@ "use strict"; | ||
_defineProperty(this, "invalidateRolesCache", function (operatorId) { | ||
return new Promise(function (resolve, reject) { | ||
_this.axios.get(_this.url + "/roles-cache-invalidate?operatorId=" + operatorId, { | ||
headers: { | ||
Accept: "application/json;charset=utf-8", | ||
"Content-Type": "application/json;charset=utf-8" | ||
} | ||
}).then(function (response) { | ||
if (response.status === 200) { | ||
resolve(); | ||
} else { | ||
reject(response); | ||
} | ||
})["catch"](function (error) { | ||
return reject(error); | ||
}); | ||
}); | ||
}); | ||
this.url = baseUrl + "/meta/current-user"; | ||
@@ -81,0 +100,0 @@ this.axios = axiosInstance ? axiosInstance : _axios["default"]; |
@@ -19,2 +19,5 @@ "use strict"; | ||
return new Promise(function () {}); | ||
}, | ||
onLogout: function onLogout() { | ||
return new Promise(function () {}); | ||
} | ||
@@ -21,0 +24,0 @@ }); |
@@ -102,3 +102,3 @@ "use strict"; | ||
if (result !== null) { | ||
return Promise.resolve(result); | ||
return resolve(result); | ||
} | ||
@@ -112,3 +112,3 @@ | ||
if (result[_roleShortName] === 1) { | ||
return Promise.resolve(true); | ||
return resolve(true); | ||
} | ||
@@ -125,2 +125,16 @@ } | ||
var onLogout = function onLogout() { | ||
return new Promise(function (resolve, reject) { | ||
if (currentUser != null && currentUser.operatorId || (currentUser == null ? void 0 : currentUser.operatorId) === 0) { | ||
userApi.invalidateRolesCache(currentUser.operatorId).then(function () { | ||
resolve(); | ||
})["catch"](function (error) { | ||
reject(error); | ||
}); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}; | ||
return /*#__PURE__*/_react["default"].createElement(_UserContext.UserContext.Provider, { | ||
@@ -131,2 +145,3 @@ value: { | ||
isUserInRoles: hasRoles, | ||
onLogout: onLogout, | ||
isRoleLoading: isRoleLoading, | ||
@@ -133,0 +148,0 @@ isUserLoading: isUserLoading |
@@ -64,2 +64,19 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
_defineProperty(this, "invalidateRolesCache", operatorId => { | ||
return new Promise((resolve, reject) => { | ||
this.axios.get(this.url + "/roles-cache-invalidate?operatorId=" + operatorId, { | ||
headers: { | ||
Accept: "application/json;charset=utf-8", | ||
"Content-Type": "application/json;charset=utf-8" | ||
} | ||
}).then(response => { | ||
if (response.status === 200) { | ||
resolve(); | ||
} else { | ||
reject(response); | ||
} | ||
}).catch(error => reject(error)); | ||
}); | ||
}); | ||
this.url = baseUrl + "/meta/current-user"; | ||
@@ -66,0 +83,0 @@ this.axios = axiosInstance ? axiosInstance : axios; |
@@ -9,3 +9,4 @@ import { createContext, useContext } from "react"; | ||
isUserInRoles: () => new Promise(() => {}), | ||
isUserInRole: () => new Promise(() => {}) | ||
isUserInRole: () => new Promise(() => {}), | ||
onLogout: () => new Promise(() => {}) | ||
}); | ||
@@ -12,0 +13,0 @@ export var useUser = () => { |
@@ -80,3 +80,3 @@ import React, { useEffect, useReducer, useContext } from "react"; | ||
if (result !== null) { | ||
return Promise.resolve(result); | ||
return resolve(result); | ||
} | ||
@@ -90,3 +90,3 @@ | ||
if (result[_roleShortName] === 1) { | ||
return Promise.resolve(true); | ||
return resolve(true); | ||
} | ||
@@ -103,2 +103,16 @@ } | ||
var onLogout = () => { | ||
return new Promise((resolve, reject) => { | ||
if (currentUser != null && currentUser.operatorId || (currentUser == null ? void 0 : currentUser.operatorId) === 0) { | ||
userApi.invalidateRolesCache(currentUser.operatorId).then(() => { | ||
resolve(); | ||
}).catch(error => { | ||
reject(error); | ||
}); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}; | ||
return /*#__PURE__*/React.createElement(UserContext.Provider, { | ||
@@ -109,2 +123,3 @@ value: { | ||
isUserInRoles: hasRoles, | ||
onLogout, | ||
isRoleLoading, | ||
@@ -111,0 +126,0 @@ isUserLoading |
@@ -10,2 +10,3 @@ import { AxiosInstance } from "axios"; | ||
isUserInRole: (roleShortName: string) => Promise<Roles>; | ||
invalidateRolesCache: (operatorId: number) => Promise<void>; | ||
} |
@@ -9,4 +9,5 @@ /// <reference types="react" /> | ||
isUserInRole: (roleShortName: string) => Promise<boolean>; | ||
onLogout?: () => Promise<void>; | ||
} | ||
export declare const UserContext: import("react").Context<IUserContext>; | ||
export declare const useUser: () => IUserContext; |
{ | ||
"name": "@jfront/oauth-user", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"license": "Apache-2.0", | ||
@@ -34,3 +34,3 @@ "repository": "https://github.com/Jepria/jfront-oauth", | ||
}, | ||
"gitHead": "bd2c4cb078d0d36351db6816ca0f9be53058bc53" | ||
"gitHead": "2821eccdd997f41d8c556e119739233860cc2f76" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
84459
729