@alfabit/keycloak 0.0.33 → 0.0.35

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.33",
4
+ "version": "0.0.35",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
7
7
  "main": "src/index.ts",
@@ -21,6 +21,7 @@
21
21
  },
22
22
  "devDependencies": {
23
23
  "@alfabit/constants": "^0.0.21",
24
+ "@alfabit/analitics": "^0.0.18",
24
25
  "@intlify/unplugin-vue-i18n": "^6.0.8",
25
26
  "@tanstack/vue-query": "^5.72.0",
26
27
  "@types/lodash-es": "^4.17.12",
@@ -1,5 +1,6 @@
1
1
  import { REF_KEY, WALLET_API_HOST } from '@alfabit/constants';
2
2
  import { getToken } from '../../../composables';
3
+ import { useAnalytics } from '@alfabit/analitics';
3
4
 
4
5
  export const postWebLogin = async () => {
5
6
  if (typeof window === 'undefined') return;
@@ -11,13 +12,27 @@ export const postWebLogin = async () => {
11
12
  const token = getToken();
12
13
  if(token) headers['Authorization'] = `Bearer ${token}`;
13
14
 
15
+ let url = `${WALLET_API_HOST}/public/web/login/`;
16
+
17
+ try {
18
+ const analytics = useAnalytics();
19
+ const clientID = await analytics.getClientID();
20
+ if (clientID) {
21
+ const urlObj = new URL(url);
22
+ urlObj.searchParams.set('ym_client_id', clientID);
23
+ url = urlObj.toString();
24
+ }
25
+ } catch (error) {
26
+ console.warn('Failed to get analytics clientID:', error);
27
+ }
28
+
14
29
  const params: RequestInit = {
15
30
  method: "POST",
16
31
  headers,
17
32
  body: JSON.stringify({ referral_token })
18
33
  }
19
34
 
20
- const res = await fetch(`${WALLET_API_HOST}/public/web/login/`, params);
35
+ const res = await fetch(url, params);
21
36
 
22
37
  if (!res.ok) {
23
38
  throw new Error(`postWebLogin /public/web/login/: HTTP error: ${res.status}`);
@@ -1,7 +1,7 @@
1
1
  import Keycloak, { type KeycloakInitOptions } from 'keycloak-js';
2
2
  import { inject, reactive, readonly, type Ref, ref } from 'vue';
3
3
  import { postWebLogin } from '../api/wallet/endpoints';
4
- import { AppNameEnum, APP_NAME, IS_TELEGRAM_MINI_APP, KEYCLOAK_LOGIN_REQUIRED, OPENID_CLIENT_ID, OPENID_REALM, OPENID_URL, LocationEnum } from '@alfabit/constants';
4
+ import { AppNameEnum, APP_NAME, IS_TELEGRAM_MINI_APP, KEYCLOAK_LOGIN_REQUIRED, OPENID_CLIENT_ID, OPENID_REALM, OPENID_URL, LocationEnum, IS_LOCALHOST } from '@alfabit/constants';
5
5
 
6
6
  export type TIdpHint = 'email' | 'google' | 'apple';
7
7
 
@@ -270,7 +270,7 @@ function clearTokens() {
270
270
  sessionStorage.removeItem(ID_TOKEN_NAME);
271
271
  }
272
272
 
273
- export const getToken = () => (IS_TELEGRAM_MINI_APP ? sessionStorage.getItem(TOKEN_NAME) : localStorage.getItem(TOKEN_NAME)) ?? undefined;
273
+ export const getToken = () => (IS_TELEGRAM_MINI_APP && !IS_LOCALHOST ? sessionStorage.getItem(TOKEN_NAME) : localStorage.getItem(TOKEN_NAME)) ?? undefined;
274
274
 
275
275
  const parseJwt = (token: unknown) => {
276
276
  if (typeof token !== 'string') throw new Error('Invalid JWT format: #1');