@alfabit/keycloak 0.0.16 → 0.0.17

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@alfabit/keycloak",
3
3
  "private": false,
4
- "version": "0.0.16",
4
+ "version": "0.0.17",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
7
7
  "main": "src/index.ts",
@@ -340,6 +340,17 @@ export async function initKeycloak() {
340
340
  clientId: OPENID_CLIENT_ID,
341
341
  });
342
342
 
343
+
344
+
345
+ keycloak.value && (keycloak.value.onAuthLogout = () => {
346
+ console.warn('>>>>>>>> Сессия истекла');
347
+ // например, показать уведомление
348
+ // или открыть собственное модальное окно логина
349
+ });
350
+
351
+
352
+
353
+
343
354
  const isNeedAuth = !!getToken() && !isRtExp();
344
355
 
345
356
  // window.opener - если находимся в popup (но не в passport), то 100% уже авторизованы и можно поставить login-required
@@ -353,12 +364,9 @@ export async function initKeycloak() {
353
364
  if (KEYCLOAK_LOGIN_REQUIRED || (window.opener && APP_NAME !== AppNameEnum.PASSPORT)) {
354
365
  initOptions.onLoad = 'login-required';
355
366
  } else if (isNeedAuth) {
356
- // initOptions.onLoad = 'check-sso';
357
-
358
- clearTokens();
359
- window.location.href = getUrl() as string;
360
-
361
-
367
+ initOptions.onLoad = 'check-sso';
368
+ // clearTokens();
369
+ // window.location.href = getUrl() as string;
362
370
  }
363
371
 
364
372
  if (!isNeedAuth) {
@@ -391,15 +399,26 @@ export async function initKeycloak() {
391
399
  //setTimeout(() => {
392
400
  setInterval(async () => {
393
401
  if (!keycloak.value) return;
394
- const res = await keycloak.value.updateToken(70);
395
- if (res) {
396
- setTokens();
397
- keycloakUserData.value = keycloak.value?.tokenParsed ?? null;
398
- isAuth.value = true;
399
- try {
400
- postWebLogin();
401
- } catch (e) {}
402
+
403
+
404
+ try{
405
+ const res = await keycloak.value.updateToken(70);
406
+ if (res) {
407
+ setTokens();
408
+ keycloakUserData.value = keycloak.value?.tokenParsed ?? null;
409
+ isAuth.value = true;
410
+ try {
411
+ postWebLogin();
412
+ } catch {}
413
+ }
402
414
  }
415
+ catch(e){
416
+ console.warn('Ошибка Keycloak:', e);
417
+ keycloak.value?.clearToken();
418
+ }
419
+
420
+
421
+
403
422
  }, 6000);
404
423
  //}, 60000);
405
424
  }