@ssplib/react-components 0.0.292 → 0.0.293
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.
|
@@ -22,6 +22,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
25
34
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
36
|
};
|
|
@@ -46,6 +55,19 @@ function KeycloakAuthProvider({ url, realm, clientId, children, type = 'ad', res
|
|
|
46
55
|
clientId: clientId,
|
|
47
56
|
});
|
|
48
57
|
setKc(keycloak);
|
|
58
|
+
keycloak.onTokenExpired = () => __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
console.log('token expired');
|
|
60
|
+
try {
|
|
61
|
+
const refreshed = yield keycloak.updateToken(5);
|
|
62
|
+
if (refreshed) {
|
|
63
|
+
setUser((prevUser) => (Object.assign(Object.assign({}, prevUser), { token: keycloak.token })));
|
|
64
|
+
}
|
|
65
|
+
console.log(refreshed ? 'Token was refreshed' : 'Token is still valid');
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
console.log('Failed to refresh token', error);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
49
71
|
keycloak
|
|
50
72
|
.init({
|
|
51
73
|
onLoad: 'check-sso',
|
|
@@ -64,9 +86,6 @@ function KeycloakAuthProvider({ url, realm, clientId, children, type = 'ad', res
|
|
|
64
86
|
const userData = Object.assign(Object.assign({}, tokenParsed), { token: keycloak.token, roles: ((_b = ((_a = tokenParsed === null || tokenParsed === void 0 ? void 0 : tokenParsed.resource_access) !== null && _a !== void 0 ? _a : {})[resource_name]) !== null && _b !== void 0 ? _b : []).roles });
|
|
65
87
|
setUser(userData);
|
|
66
88
|
console.info('Authenticated!!!');
|
|
67
|
-
keycloak.onTokenExpired = () => {
|
|
68
|
-
console.log('token expired');
|
|
69
|
-
};
|
|
70
89
|
}
|
|
71
90
|
}, () => {
|
|
72
91
|
console.error('Authenticated Failed');
|