@alfabit/keycloak 0.0.15 → 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.15",
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
@@ -354,6 +365,8 @@ export async function initKeycloak() {
354
365
  initOptions.onLoad = 'login-required';
355
366
  } else if (isNeedAuth) {
356
367
  initOptions.onLoad = 'check-sso';
368
+ // clearTokens();
369
+ // window.location.href = getUrl() as string;
357
370
  }
358
371
 
359
372
  if (!isNeedAuth) {
@@ -386,15 +399,26 @@ export async function initKeycloak() {
386
399
  //setTimeout(() => {
387
400
  setInterval(async () => {
388
401
  if (!keycloak.value) return;
389
- const res = await keycloak.value.updateToken(70);
390
- if (res) {
391
- setTokens();
392
- keycloakUserData.value = keycloak.value?.tokenParsed ?? null;
393
- isAuth.value = true;
394
- try {
395
- postWebLogin();
396
- } 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
+ }
414
+ }
415
+ catch(e){
416
+ console.warn('Ошибка Keycloak:', e);
417
+ keycloak.value?.clearToken();
397
418
  }
419
+
420
+
421
+
398
422
  }, 6000);
399
423
  //}, 60000);
400
424
  }