@alfabit/keycloak 0.0.4 → 0.0.6

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.4",
4
+ "version": "0.0.6",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
7
7
  "main": "src/index.ts",
@@ -13,6 +13,9 @@
13
13
  "build": "vue-tsc -b && vite build",
14
14
  "upgrade:alfabit-constants": "yarn upgrade @alfabit/constants --latest"
15
15
  },
16
+ "dependencies": {
17
+ "keycloak-js": "^26.2.0"
18
+ },
16
19
  "devDependencies": {
17
20
  "@alfabit/constants": "^0.0.9",
18
21
  "@intlify/unplugin-vue-i18n": "^6.0.8",
@@ -164,7 +164,7 @@ export const getAuthMethods = ({ dontChangeRedirectUri = ref(false), keycloakRed
164
164
  if (keycloak.value) {
165
165
  keycloak.value.login({
166
166
  redirectUri: redirectUri ?? getUrl(dontChangeRedirectUri.value, keycloakRedirectUriIsLogout.value),
167
- loginHint: email,
167
+ loginHint: email ?? '',
168
168
  });
169
169
  } else {
170
170
  console.warn('Keycloak not defined! #login');
@@ -187,7 +187,7 @@ export const getAuthMethods = ({ dontChangeRedirectUri = ref(false), keycloakRed
187
187
  if (keycloak.value) {
188
188
  keycloak.value.register({
189
189
  redirectUri: redirectUri ?? getUrl(dontChangeRedirectUri.value),
190
- loginHint: email,
190
+ loginHint: email ?? '',
191
191
  });
192
192
  } else {
193
193
  console.warn('Keycloak not defined! #register');
@@ -346,18 +346,28 @@ export async function initKeycloak() {
346
346
 
347
347
  // window.opener - если находимся в popup (но не в passport), то 100% уже авторизованы и можно поставить login-required
348
348
  const initOptions: KeycloakInitOptions = {
349
- onLoad: KEYCLOAK_LOGIN_REQUIRED || (window.opener && APP_NAME !== AppNameEnum.PASSPORT) ? 'login-required' : isNeedAuth ? 'check-sso' : undefined, // 'none' | 'login-required' | 'check-sso', // если оставить всегда check-sso = то при разлогине, будет бесконечный редирект
350
349
  pkceMethod: 'S256',
351
350
  checkLoginIframe: false,
352
351
  // enableLogging: true,
353
352
  };
354
353
 
354
+ // Устанавливаем onLoad только если нужно
355
+ if (KEYCLOAK_LOGIN_REQUIRED || (window.opener && APP_NAME !== AppNameEnum.PASSPORT)) {
356
+ initOptions.onLoad = 'login-required';
357
+ } else if (isNeedAuth) {
358
+ initOptions.onLoad = 'check-sso';
359
+ }
360
+
355
361
  if (!isNeedAuth) {
356
362
  clearTokens();
357
363
  } else {
358
- initOptions.token = localStorage.getItem(TOKEN_NAME) ?? undefined;
359
- initOptions.refreshToken = localStorage.getItem(REFRESH_TOKEN_NAME) ?? undefined;
360
- initOptions.idToken = localStorage.getItem(ID_TOKEN_NAME) ?? undefined;
364
+ const token = localStorage.getItem(TOKEN_NAME);
365
+ const refreshToken = localStorage.getItem(REFRESH_TOKEN_NAME);
366
+ const idToken = localStorage.getItem(ID_TOKEN_NAME);
367
+
368
+ if (token) initOptions.token = token;
369
+ if (refreshToken) initOptions.refreshToken = refreshToken;
370
+ if (idToken) initOptions.idToken = idToken;
361
371
  }
362
372
 
363
373
  console.log({
package/src/index.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './plugins/keycloak';
2
+ export * from './composables';