@alfabit/keycloak 0.0.42 → 0.0.43

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.42",
4
+ "version": "0.0.43",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
7
7
  "main": "src/index.ts",
@@ -82,21 +82,21 @@ const locale = ref('en');
82
82
  const dontChangeRedirectUri = ref(false);
83
83
  const keycloakRedirectUriIsLogout = ref<string | undefined>(undefined);
84
84
 
85
- export const setKeycloakLocale = (newLocale: LocationEnum) => {
85
+ export function setKeycloakLocale(newLocale: LocationEnum) {
86
86
  locale.value = newLocale;
87
87
  };
88
88
 
89
- export const setDontChangeRedirectUri = (newDontChangeRedirectUri: boolean) => {
89
+ export function setDontChangeRedirectUri(newDontChangeRedirectUri: boolean) {
90
90
  dontChangeRedirectUri.value = newDontChangeRedirectUri;
91
91
  };
92
92
 
93
- export const setKeycloakRedirectUriIsLogout = (newKeycloakRedirectUriIsLogout: string | undefined) => {
93
+ export function setKeycloakRedirectUriIsLogout(newKeycloakRedirectUriIsLogout: string | undefined) {
94
94
  keycloakRedirectUriIsLogout.value = newKeycloakRedirectUriIsLogout;
95
95
  };
96
96
 
97
97
  const isInitialized = ref(false);
98
98
 
99
- const getUrl = (): string => {
99
+ function getUrl(): string {
100
100
  const url = new URL(window.location.href);
101
101
  const searchParams = new URLSearchParams(window.location.search);
102
102
 
@@ -138,8 +138,8 @@ function isMobile() {
138
138
  return /Mobi|Android|iPhone|iPad|iPod/i.test(navigator.userAgent);
139
139
  }
140
140
 
141
- export const getAuthMethods = () => {
142
- const methods = reactive({
141
+ export function getAuthMethods() {
142
+ const methods = {
143
143
  async loginPopup(idpHint: TIdpHint, redirectUri?: string) {
144
144
  redirectUri = redirectUri ?? getUrl();
145
145
  if (isMobile()) {
@@ -289,7 +289,7 @@ export const getAuthMethods = () => {
289
289
  console.warn('Keycloak not defined! #configureOtp');
290
290
  }
291
291
  },
292
- });
292
+ };
293
293
  return methods;
294
294
  };
295
295
 
@@ -314,9 +314,11 @@ function clearTokens() {
314
314
  sessionStorage.removeItem(ID_TOKEN_NAME);
315
315
  }
316
316
 
317
- export const getToken = () => (IS_TELEGRAM_MINI_APP && !IS_LOCALHOST ? sessionStorage.getItem(TOKEN_NAME) : localStorage.getItem(TOKEN_NAME)) ?? undefined;
317
+ export function getToken() {
318
+ return (IS_TELEGRAM_MINI_APP && !IS_LOCALHOST ? sessionStorage.getItem(TOKEN_NAME) : localStorage.getItem(TOKEN_NAME)) ?? undefined;
319
+ }
318
320
 
319
- const parseJwt = (token: unknown) => {
321
+ function parseJwt(token: unknown) {
320
322
  if (typeof token !== 'string') throw new Error('Invalid JWT format: #1');
321
323
  const [headerB64, payloadB64] = token.split('.');
322
324
  if (!headerB64 || !payloadB64) throw new Error('Invalid JWT format: #2');
@@ -333,7 +335,7 @@ const parseJwt = (token: unknown) => {
333
335
  };
334
336
  };
335
337
 
336
- export const isAtExp = () => {
338
+ export function isAtExp() {
337
339
  if (typeof window === 'undefined') return false;
338
340
  try {
339
341
  return parseJwt(localStorage.getItem(TOKEN_NAME)).isExpired;
@@ -342,7 +344,7 @@ export const isAtExp = () => {
342
344
  }
343
345
  };
344
346
 
345
- export const isRtExp = () => {
347
+ export function isRtExp() {
346
348
  if (typeof window === 'undefined') return false;
347
349
  try {
348
350
  // если рт не истек, возвращаем true
@@ -518,7 +520,7 @@ export async function createKeycloakInit({ keycloakInit }: IKeycliakInit = {}) {
518
520
 
519
521
  let _keycloakInit: IUseKeycloak | null = null;
520
522
 
521
- export const keycloakInit = (dontChangeRedirectUri?: Ref<boolean>, keycloakRedirectUriIsLogout?: Ref<string | undefined>): IUseKeycloak => {
523
+ export function keycloakInit(dontChangeRedirectUri?: Ref<boolean>, keycloakRedirectUriIsLogout?: Ref<string | undefined>): IUseKeycloak {
522
524
  if (_keycloakInit) return _keycloakInit;
523
525
 
524
526
  dontChangeRedirectUri ||= inject('dontChangeRedirectUri', ref(false));