update keycloak

This commit is contained in:
Mohamadzadeh 2026-06-13 10:44:32 +03:30
parent 7f947d5cd8
commit 0a65628ec3
2 changed files with 87 additions and 90 deletions

158
dist/index.js vendored
View File

@ -5,11 +5,11 @@ var Se = (r) => {
var je = (r, e, t) => e in r ? Pe(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
var f = (r, e, t) => je(r, typeof e != "symbol" ? e + "" : e, t), oe = (r, e, t) => e.has(r) || Se("Cannot " + t);
var h = (r, e, t) => (oe(r, e, "read from private field"), t ? t.call(r) : e.get(r)), A = (r, e, t) => e.has(r) ? Se("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(r) : e.set(r, t), B = (r, e, t, i) => (oe(r, e, "write to private field"), i ? i.call(r, t) : e.set(r, t), t), d = (r, e, t) => (oe(r, e, "access private method"), t);
import { jsxs as O, jsx as S } from "react/jsx-runtime";
import { useState as I, useRef as ie, useEffect as W, useCallback as H, createContext as Oe, useMemo as We } from "react";
import { HStack as N, IconButton as G, Button as ke, Input as be, Text as j } from "@chakra-ui/react";
import { jsxs as W, jsx as S } from "react/jsx-runtime";
import { useState as I, useRef as ie, useEffect as O, useCallback as H, createContext as We, useMemo as Oe } from "react";
import { HStack as K, IconButton as G, Button as ke, Input as be, Text as j } from "@chakra-ui/react";
import { IoChevronForwardOutline as ye, IoChevronBackOutline as ve } from "react-icons/io5";
const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => String(r).replace(/\d/g, (e) => "۰۱۲۳۴۵۶۷۸۹"[Number(e)]), V = (r) => String(r).replace(/[۰-۹]/g, (t) => String("۰۱۲۳۴۵۶۷۸۹".indexOf(t))), vt = ({
const kt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => String(r).replace(/\d/g, (e) => "۰۱۲۳۴۵۶۷۸۹"[Number(e)]), V = (r) => String(r).replace(/[۰-۹]/g, (t) => String("۰۱۲۳۴۵۶۷۸۹".indexOf(t))), bt = ({
currentPage: r,
totalPages: e,
totalCount: t,
@ -18,13 +18,13 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => S
const [n, o] = I(v(r)), [c, a] = I(!1), [l, u] = I(null), w = ie(null), m = [.../* @__PURE__ */ new Set([1, r, e])].filter(
(p) => p >= 1 && p <= e
);
W(() => {
O(() => {
if (l !== null) {
r === l && (u(null), a(!1), o(v(r)));
return;
}
c || o(v(r));
}, [r, c, l]), W(() => {
}, [r, c, l]), O(() => {
if (!c || !n || l !== null) return;
const p = parseInt(V(n), 10);
if (isNaN(p)) return;
@ -52,8 +52,8 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => S
const k = Math.min(Math.max(p, 1), e);
k !== r ? (u(k), o(v(k)), i(k)) : (o(v(r)), a(!1), u(null)), (C = w.current) == null || C.blur();
};
return e === 0 || !t ? null : /* @__PURE__ */ O(
N,
return e === 0 || !t ? null : /* @__PURE__ */ W(
K,
{
justifyContent: "space-around",
backgroundColor: "white",
@ -64,7 +64,7 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => S
borderColor: "blue.200",
w: "100%",
children: [
/* @__PURE__ */ O(N, { spacing: 2, alignItems: "center", justifyContent: "center", children: [
/* @__PURE__ */ W(K, { spacing: 2, alignItems: "center", justifyContent: "center", children: [
/* @__PURE__ */ S(
G,
{
@ -135,14 +135,14 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => S
}
)
] }),
/* @__PURE__ */ O(N, { spacing: 2, children: [
/* @__PURE__ */ W(K, { spacing: 2, children: [
/* @__PURE__ */ S(j, { w: "auto", fontWeight: "bold", whiteSpace: "nowrap", children: "تعداد کل:" }),
/* @__PURE__ */ S(j, { children: v(t) })
] })
]
}
);
}, St = ({
}, yt = ({
currentPage: r,
totalPages: e,
totalCount: t,
@ -151,13 +151,13 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => S
const [n, o] = I(v(r)), [c, a] = I(!1), [l, u] = I(null), w = ie(null), m = Array.from(
/* @__PURE__ */ new Set([1, r, r + 1, e])
).filter((p) => p >= 1 && p <= e).sort((p, k) => p - k);
W(() => {
O(() => {
if (l !== null) {
r === l && (u(null), a(!1), o(v(r)));
return;
}
c || o(v(r));
}, [r, c, l]), W(() => {
}, [r, c, l]), O(() => {
if (!c || !n || l !== null) return;
const p = parseInt(V(n), 10);
if (isNaN(p)) return;
@ -185,8 +185,8 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => S
const k = Math.min(Math.max(p, 1), e);
k !== r ? (u(k), o(v(k)), i(k)) : (o(v(r)), a(!1), u(null)), (C = w.current) == null || C.blur();
};
return e === 0 || !t ? null : /* @__PURE__ */ O(
N,
return e === 0 || !t ? null : /* @__PURE__ */ W(
K,
{
justifyContent: "space-around",
backgroundColor: "white",
@ -197,13 +197,13 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => S
borderColor: "blue.200",
w: "100%",
children: [
/* @__PURE__ */ O(N, { spacing: 2, whiteSpace: "nowrap", children: [
/* @__PURE__ */ W(K, { spacing: 2, whiteSpace: "nowrap", children: [
/* @__PURE__ */ S(j, { fontWeight: "bold", children: "صفحه" }),
/* @__PURE__ */ S(j, { children: v(r) }),
/* @__PURE__ */ S(j, { fontWeight: "bold", children: "از" }),
/* @__PURE__ */ S(j, { children: v(e) })
] }),
/* @__PURE__ */ O(N, { spacing: 2, alignItems: "center", justifyContent: "center", children: [
/* @__PURE__ */ W(K, { spacing: 2, alignItems: "center", justifyContent: "center", children: [
/* @__PURE__ */ S(
G,
{
@ -273,14 +273,14 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => S
}
)
] }),
/* @__PURE__ */ O(N, { spacing: 2, whiteSpace: "nowrap", children: [
/* @__PURE__ */ W(K, { spacing: 2, whiteSpace: "nowrap", children: [
/* @__PURE__ */ S(j, { fontWeight: "bold", children: "تعداد کل:" }),
/* @__PURE__ */ S(j, { children: v(t) })
] })
]
}
);
}, Ct = ({
}, vt = ({
currentPage: r,
totalPages: e,
totalCount: t,
@ -305,12 +305,12 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => S
const E = Math.min(Math.max(U, 1), e);
a(!1), o(""), E !== r ? (u(E), i(E)) : u(null);
}, [n, r, e, i]);
W(() => {
O(() => {
var U;
c && ((U = w.current) == null || U.focus());
}, [c]), W(() => {
}, [c]), O(() => {
l !== null && r === l && u(null);
}, [r, l]), W(() => {
}, [r, l]), O(() => {
if (!c || !n) return;
const U = setTimeout(() => {
p();
@ -335,7 +335,7 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => S
if (e === 0 || !t) return null;
const C = e > 1 && m !== 1, F = e > 1 && m !== e;
return /* @__PURE__ */ S(
N,
K,
{
justifyContent: "center",
backgroundColor: "white",
@ -345,7 +345,7 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => S
border: "1px",
borderColor: "blue.200",
w: "100%",
children: /* @__PURE__ */ O(N, { spacing: 2, alignItems: "center", justifyContent: "center", children: [
children: /* @__PURE__ */ W(K, { spacing: 2, alignItems: "center", justifyContent: "center", children: [
/* @__PURE__ */ S(
G,
{
@ -404,7 +404,7 @@ const yt = (r) => new Intl.NumberFormat("fa-IR").format(Number(r)), v = (r) => S
}
);
}, Ve = "application/json";
var K, _, $, J, M, q, y, L, s, ee, _e, Ee, Ae, Ie, ae, xe, ce, Le, Re, te, X, le, z, Me, de, P, re, Z, R, ue;
var N, _, J, Y, M, q, y, L, s, ee, _e, Ee, Ae, Ie, ae, xe, ce, Le, Re, te, X, le, z, Me, de, P, re, Z, R, ue;
class Fe {
/**
* @param {KeycloakConfig} config
@ -412,13 +412,13 @@ class Fe {
constructor(e) {
A(this, s);
/** @type {Pick<PromiseWithResolvers<boolean>, 'resolve' | 'reject'>[]} */
A(this, K, []);
A(this, N, []);
/** @type {KeycloakAdapter} */
A(this, _);
/** @type {boolean} */
A(this, $, !0);
A(this, J, !0);
/** @type {CallbackStorage} */
A(this, J);
A(this, Y);
A(this, M, d(this, s, ue).call(this, console.info));
A(this, q, d(this, s, ue).call(this, console.warn));
/** @type {LoginIframe} */
@ -512,9 +512,9 @@ class Fe {
var i;
if (this.didInitialize)
throw new Error("A 'Keycloak' instance can only be initialized once.");
this.didInitialize = !0, B(this, J, Qe());
this.didInitialize = !0, B(this, Y, Qe());
const t = ["default", "cordova", "cordova-native"];
if (typeof e.adapter == "string" && t.includes(e.adapter) ? B(this, _, d(this, s, ee).call(this, e.adapter)) : typeof e.adapter == "object" ? B(this, _, e.adapter) : "Cordova" in window || "cordova" in window ? B(this, _, d(this, s, ee).call(this, "cordova")) : B(this, _, d(this, s, ee).call(this, "default")), typeof e.useNonce < "u" && B(this, $, e.useNonce), typeof e.checkLoginIframe < "u" && (h(this, y).enable = e.checkLoginIframe), e.checkLoginIframeInterval && (h(this, y).interval = e.checkLoginIframeInterval), e.onLoad === "login-required" && (this.loginRequired = !0), e.responseMode)
if (typeof e.adapter == "string" && t.includes(e.adapter) ? B(this, _, d(this, s, ee).call(this, e.adapter)) : typeof e.adapter == "object" ? B(this, _, e.adapter) : "Cordova" in window || "cordova" in window ? B(this, _, d(this, s, ee).call(this, "cordova")) : B(this, _, d(this, s, ee).call(this, "default")), typeof e.useNonce < "u" && B(this, J, e.useNonce), typeof e.checkLoginIframe < "u" && (h(this, y).enable = e.checkLoginIframe), e.checkLoginIframeInterval && (h(this, y).interval = e.checkLoginIframeInterval), e.onLoad === "login-required" && (this.loginRequired = !0), e.responseMode)
if (e.responseMode === "query" || e.responseMode === "fragment")
this.responseMode = e.responseMode;
else
@ -575,14 +575,14 @@ class Fe {
["response_type", this.responseType],
["scope", a]
]);
if (h(this, $) && u.append("nonce", i), e != null && e.prompt && u.append("prompt", e.prompt), typeof (e == null ? void 0 : e.maxAge) == "number" && u.append("max_age", e.maxAge.toString()), e != null && e.loginHint && u.append("login_hint", e.loginHint), e != null && e.idpHint && u.append("kc_idp_hint", e.idpHint), e != null && e.action && e.action !== "register" && u.append("kc_action", e.action), e != null && e.locale && u.append("ui_locales", e.locale), e != null && e.acr && u.append("claims", He(e.acr)), e != null && e.acrValues && u.append("acr_values", e.acrValues), this.pkceMethod)
if (h(this, J) && u.append("nonce", i), e != null && e.prompt && u.append("prompt", e.prompt), typeof (e == null ? void 0 : e.maxAge) == "number" && u.append("max_age", e.maxAge.toString()), e != null && e.loginHint && u.append("login_hint", e.loginHint), e != null && e.idpHint && u.append("kc_idp_hint", e.idpHint), e != null && e.action && e.action !== "register" && u.append("kc_action", e.action), e != null && e.locale && u.append("ui_locales", e.locale), e != null && e.acr && u.append("claims", He(e.acr)), e != null && e.acrValues && u.append("acr_values", e.acrValues), this.pkceMethod)
try {
const w = Ye(96), m = await $e(this.pkceMethod, w);
const w = $e(96), m = await Je(this.pkceMethod, w);
o.pkceCodeVerifier = w, u.append("code_challenge", m), u.append("code_challenge_method", this.pkceMethod);
} catch (w) {
throw new Error("Failed to generate PKCE challenge.", { cause: w });
}
return h(this, J).add(o), `${c}?${u.toString()}`;
return h(this, Y).add(o), `${c}?${u.toString()}`;
});
/**
* @param {KeycloakLogoutOptions} [options]
@ -712,7 +712,7 @@ class Fe {
if (e === -1 ? (t = !0, h(this, M).call(this, "[KEYCLOAK] Refreshing token: forced refresh")) : (!this.tokenParsed || this.isTokenExpired(e)) && (t = !0, h(this, M).call(this, "[KEYCLOAK] Refreshing token: token expired")), !t)
return !1;
const { promise: i, resolve: n, reject: o } = Promise.withResolvers();
if (h(this, K).push({ resolve: n, reject: o }), h(this, K).length === 1) {
if (h(this, N).push({ resolve: n, reject: o }), h(this, N).length === 1) {
const l = this.endpoints.token();
let u = (/* @__PURE__ */ new Date()).getTime();
try {
@ -723,11 +723,11 @@ class Fe {
this.clientId
);
h(this, M).call(this, "[KEYCLOAK] Token refreshed"), u = (u + (/* @__PURE__ */ new Date()).getTime()) / 2, d(this, s, Z).call(this, w.access_token, w.refresh_token, w.id_token, u), (c = this.onAuthRefreshSuccess) == null || c.call(this);
for (let m = h(this, K).pop(); m != null; m = h(this, K).pop())
for (let m = h(this, N).pop(); m != null; m = h(this, N).pop())
m.resolve(!0);
} catch (w) {
h(this, q).call(this, "[KEYCLOAK] Failed to refresh token"), w instanceof Be && w.response.status === 400 && this.clearToken(), (a = this.onAuthRefreshError) == null || a.call(this);
for (let m = h(this, K).pop(); m != null; m = h(this, K).pop())
for (let m = h(this, N).pop(); m != null; m = h(this, N).pop())
m.reject(w);
}
}
@ -751,7 +751,7 @@ Continuing to run your application insecurely will lead to unexpected behavior a
For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts`), B(this, L, e);
}
}
K = new WeakMap(), _ = new WeakMap(), $ = new WeakMap(), J = new WeakMap(), M = new WeakMap(), q = new WeakMap(), y = new WeakMap(), L = new WeakMap(), s = new WeakSet(), /**
N = new WeakMap(), _ = new WeakMap(), J = new WeakMap(), Y = new WeakMap(), M = new WeakMap(), q = new WeakMap(), y = new WeakMap(), L = new WeakMap(), s = new WeakSet(), /**
* @param {"default" | "cordova" | "cordova-native"} type
* @returns {KeycloakAdapter}
*/
@ -1104,7 +1104,7 @@ z = function(e) {
const t = d(this, s, Me).call(this, e);
if (!t)
return;
const i = h(this, J).get(t.state);
const i = h(this, Y).get(t.state);
return i && (t.valid = !0, t.redirectUri = i.redirectUri, t.storedNonce = i.nonce, t.prompt = i.prompt, t.pkceCodeVerifier = i.pkceCodeVerifier, t.loginOptions = i.loginOptions), t;
}, /**
* @param {string} urlString
@ -1163,7 +1163,7 @@ de = function(e, t) {
const { code: t, error: i, prompt: n } = e;
let o = (/* @__PURE__ */ new Date()).getTime();
const c = (m, T, p) => {
if (o = (o + (/* @__PURE__ */ new Date()).getTime()) / 2, d(this, s, Z).call(this, m, T, p, o), h(this, $) && this.idTokenParsed && this.idTokenParsed.nonce !== e.storedNonce)
if (o = (o + (/* @__PURE__ */ new Date()).getTime()) / 2, d(this, s, Z).call(this, m, T, p, o), h(this, J) && this.idTokenParsed && this.idTokenParsed.nonce !== e.storedNonce)
throw h(this, M).call(this, "[KEYCLOAK] Invalid nonce, clearing token"), this.clearToken(), new Error("Invalid nonce.");
};
if (e.kc_action_status && this.onActionUpdate && this.onActionUpdate(e.kc_action_status, e.kc_action), i) {
@ -1236,16 +1236,16 @@ function He(r) {
}
});
}
function Ye(r) {
return Je(r, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
function $e(r) {
return Ye(r, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
}
async function $e(r, e) {
async function Je(r, e) {
if (r !== "S256")
throw new TypeError(`Invalid value for 'pkceMethod', expected 'S256' but got '${r}'.`);
const t = new Uint8Array(await tt(e));
return et(t).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
}
function Je(r, e) {
function Ye(r, e) {
const t = qe(r), i = new Array(r);
for (let n = 0; n < r; n++)
i[n] = e.charCodeAt(t[n] % e.length);
@ -1274,8 +1274,8 @@ function Qe() {
return new Ze();
}
}
const Y = "kc-callback-";
var x, he, De, fe, Ke;
const $ = "kc-callback-";
var x, he, De, fe, Ne;
class Xe {
constructor() {
A(this, x);
@ -1289,7 +1289,7 @@ class Xe {
if (!e)
return null;
d(this, x, he).call(this);
const t = Y + e, i = globalThis.localStorage.getItem(t);
const t = $ + e, i = globalThis.localStorage.getItem(t);
return i ? (globalThis.localStorage.removeItem(t), JSON.parse(i)) : null;
}
/**
@ -1297,7 +1297,7 @@ class Xe {
*/
add(e) {
d(this, x, he).call(this);
const t = Y + e.state, i = JSON.stringify({
const t = $ + e.state, i = JSON.stringify({
...e,
// Set the expiry time to 1 hour from now.
expires: Date.now() + 60 * 60 * 1e3
@ -1315,7 +1315,7 @@ x = new WeakSet(), /**
he = function() {
const e = Date.now();
for (const [t, i] of d(this, x, fe).call(this)) {
const n = d(this, x, Ke).call(this, i);
const n = d(this, x, Ne).call(this, i);
(n === null || n < e) && globalThis.localStorage.removeItem(t);
}
}, /**
@ -1329,13 +1329,13 @@ De = function() {
* @returns {[string, string][]} An array of key-value pairs.
*/
fe = function() {
return Object.entries(globalThis.localStorage).filter(([e]) => e.startsWith(Y));
return Object.entries(globalThis.localStorage).filter(([e]) => e.startsWith($));
}, /**
* Parses the expiry time from a value stored in local storage.
* @param {string} value
* @returns {number | null} The expiry time in milliseconds, or `null` if the value is malformed.
*/
Ke = function(e) {
Ne = function(e) {
let t;
try {
t = JSON.parse(e);
@ -1344,7 +1344,7 @@ Ke = function(e) {
}
return me(t) && "expires" in t && typeof t.expires == "number" ? t.expires : null;
};
var D, Ne, pe, we;
var D, Ke, pe, we;
class Ze {
constructor() {
A(this, D);
@ -1356,21 +1356,21 @@ class Ze {
get(e) {
if (!e)
return null;
const t = d(this, D, Ne).call(this, Y + e);
return d(this, D, pe).call(this, Y + e, "", d(this, D, we).call(this, -100)), t ? JSON.parse(t) : null;
const t = d(this, D, Ke).call(this, $ + e);
return d(this, D, pe).call(this, $ + e, "", d(this, D, we).call(this, -100)), t ? JSON.parse(t) : null;
}
/**
* @param {CallbackState} state
*/
add(e) {
d(this, D, pe).call(this, Y + e.state, JSON.stringify(e), d(this, D, we).call(this, 60));
d(this, D, pe).call(this, $ + e.state, JSON.stringify(e), d(this, D, we).call(this, 60));
}
}
D = new WeakSet(), /**
* @param {string} key
* @returns
*/
Ne = function(e) {
Ke = function(e) {
const t = e + "=", i = document.cookie.split(";");
for (let n = 0; n < i.length; n++) {
let o = i[n];
@ -1515,14 +1515,14 @@ class Be extends Error {
this.response = i.response;
}
}
const lt = (r) => new Promise((e) => setTimeout(e, r)), dt = "https://auth.ibagher.ir", ut = "bi";
const lt = (r) => new Promise((e) => setTimeout(e, r));
let b = null, se = null, ge = !1;
const ht = Oe(null), ft = (r) => (b || (b = new Fe({
url: dt,
realm: ut,
clientId: r
})), b), pt = ({ clientId: r, initOptions: e = {} }) => {
const t = ft(r);
const dt = We(null), ut = ({ url: r, realm: e, clientId: t }) => (b || (b = new Fe({
url: r,
realm: e,
clientId: t
})), b), ht = ({ config: r, initOptions: e = {} }) => {
const t = ut(r);
return se || (se = t.init({
onLoad: "login-required",
checkLoginIframe: !1,
@ -1531,16 +1531,16 @@ const ht = Oe(null), ft = (r) => (b || (b = new Fe({
}).then((i) => (ge = !0, i)).catch((i) => {
throw ge = !0, i;
})), se;
}, Tt = () => ge, Ut = () => !!(b != null && b.authenticated), _t = () => (b == null ? void 0 : b.token) ?? null, Et = async (r = 30) => b ? b.updateToken(r) : !1, At = (r) => b == null ? void 0 : b.logout(r), It = (r) => b == null ? void 0 : b.login(r), xt = ({
}, St = () => ge, Ct = () => !!(b != null && b.authenticated), Tt = () => (b == null ? void 0 : b.token) ?? null, Ut = async (r = 30) => b ? b.updateToken(r) : !1, _t = (r) => b == null ? void 0 : b.logout(r), Et = (r) => b == null ? void 0 : b.login(r), At = ({
children: r,
clientId: e,
config: e,
initOptions: t,
loading: i = null
}) => {
const [n, o] = I(!1), [c, a] = I(!1), [l, u] = I(null), w = ie(!1), m = H(() => {
b && (a(!!b.authenticated), u(b.token ?? null));
}, []);
W(() => (w.current = !0, pt({ clientId: e, initOptions: t }).then((C) => {
O(() => (w.current = !0, ht({ config: e, initOptions: t }).then((C) => {
w.current && (a(!!C), u((b == null ? void 0 : b.token) ?? null), o(!0));
}).catch(() => {
w.current && (a(!1), u(null), o(!0));
@ -1554,7 +1554,7 @@ const ht = Oe(null), ft = (r) => (b || (b = new Fe({
return m(), F;
},
[m]
), g = We(
), g = Oe(
() => ({
initialized: n,
authenticated: c,
@ -1565,21 +1565,21 @@ const ht = Oe(null), ft = (r) => (b || (b = new Fe({
}),
[n, c, l, T, p, k]
);
return n ? /* @__PURE__ */ S(ht.Provider, { value: g, children: r }) : i;
return n ? /* @__PURE__ */ S(dt.Provider, { value: g, children: r }) : i;
};
export {
xt as KeycloakProvider,
vt as LightPagination,
St as Pagination,
Ct as SimplePagination,
_t as getKeycloakToken,
pt as initKeycloak,
Ut as isKeycloakAuthenticated,
Tt as isKeycloakInitialized,
It as loginKeycloak,
At as logoutKeycloak,
At as KeycloakProvider,
bt as LightPagination,
yt as Pagination,
vt as SimplePagination,
Tt as getKeycloakToken,
ht as initKeycloak,
Ct as isKeycloakAuthenticated,
St as isKeycloakInitialized,
Et as loginKeycloak,
_t as logoutKeycloak,
V as toEnDigits,
v as toFaDigits,
yt as toFaNumber,
Et as updateKeycloakToken
kt as toFaNumber,
Ut as updateKeycloakToken
};

View File

@ -9,28 +9,25 @@ import {
useState,
} from "react";
const KEYCLOAK_URL = "https://auth.ibagher.ir";
const KEYCLOAK_REALM = "bi";
let keycloakInstance = null;
let initPromise = null;
let initializedValue = false;
const KeycloakContext = createContext(null);
const createKeycloak = (clientId) => {
const createKeycloak = ({ url, realm, clientId }) => {
if (!keycloakInstance) {
keycloakInstance = new Keycloak({
url: KEYCLOAK_URL,
realm: KEYCLOAK_REALM,
url,
realm,
clientId,
});
}
return keycloakInstance;
};
export const initKeycloak = ({ clientId, initOptions = {} }) => {
const keycloak = createKeycloak(clientId);
export const initKeycloak = ({ config, initOptions = {} }) => {
const keycloak = createKeycloak(config);
if (!initPromise) {
initPromise = keycloak
.init({
@ -79,7 +76,7 @@ export const loginKeycloak = (options) => {
export const KeycloakProvider = ({
children,
clientId,
config,
initOptions,
loading = null,
}) => {
@ -96,7 +93,7 @@ export const KeycloakProvider = ({
useEffect(() => {
mountedRef.current = true;
initKeycloak({ clientId, initOptions })
initKeycloak({ config, initOptions })
.then((auth) => {
if (!mountedRef.current) return;
setAuthenticated(Boolean(auth));
@ -112,7 +109,7 @@ export const KeycloakProvider = ({
return () => {
mountedRef.current = false;
};
}, [clientId, initOptions]);
}, [config, initOptions]);
const login = useCallback(() => {
return keycloakInstance?.login();