@alfabit/keycloak 0.0.16 → 0.0.18

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.18",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
7
7
  "main": "src/index.ts",
@@ -223,6 +223,17 @@ export const getAuthMethods = () => {
223
223
  console.warn('Keycloak not defined! #loginWithTelegram');
224
224
  }
225
225
  },
226
+ changePassword(redirectUri?: string) {
227
+ if (keycloak.value) {
228
+ document.cookie = 'from=passport; SameSite=None; Secure';
229
+ void keycloak.value.login({
230
+ action: 'UPDATE_PASSWORD',
231
+ redirectUri: redirectUri ?? getUrl(),
232
+ });
233
+ } else {
234
+ console.warn('Keycloak not defined! #changePassword');
235
+ }
236
+ },
226
237
  });
227
238
  return methods;
228
239
  };
@@ -340,6 +351,17 @@ export async function initKeycloak() {
340
351
  clientId: OPENID_CLIENT_ID,
341
352
  });
342
353
 
354
+
355
+
356
+ keycloak.value && (keycloak.value.onAuthLogout = () => {
357
+ console.warn('>>>>>>>> Сессия истекла');
358
+ // например, показать уведомление
359
+ // или открыть собственное модальное окно логина
360
+ });
361
+
362
+
363
+
364
+
343
365
  const isNeedAuth = !!getToken() && !isRtExp();
344
366
 
345
367
  // window.opener - если находимся в popup (но не в passport), то 100% уже авторизованы и можно поставить login-required
@@ -353,12 +375,9 @@ export async function initKeycloak() {
353
375
  if (KEYCLOAK_LOGIN_REQUIRED || (window.opener && APP_NAME !== AppNameEnum.PASSPORT)) {
354
376
  initOptions.onLoad = 'login-required';
355
377
  } else if (isNeedAuth) {
356
- // initOptions.onLoad = 'check-sso';
357
-
358
- clearTokens();
359
- window.location.href = getUrl() as string;
360
-
361
-
378
+ initOptions.onLoad = 'check-sso';
379
+ // clearTokens();
380
+ // window.location.href = getUrl() as string;
362
381
  }
363
382
 
364
383
  if (!isNeedAuth) {
@@ -391,15 +410,26 @@ export async function initKeycloak() {
391
410
  //setTimeout(() => {
392
411
  setInterval(async () => {
393
412
  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) {}
413
+
414
+
415
+ try{
416
+ const res = await keycloak.value.updateToken(70);
417
+ if (res) {
418
+ setTokens();
419
+ keycloakUserData.value = keycloak.value?.tokenParsed ?? null;
420
+ isAuth.value = true;
421
+ try {
422
+ postWebLogin();
423
+ } catch {}
424
+ }
425
+ }
426
+ catch(e){
427
+ console.warn('Ошибка Keycloak:', e);
428
+ keycloak.value?.clearToken();
402
429
  }
430
+
431
+
432
+
403
433
  }, 6000);
404
434
  //}, 60000);
405
435
  }