@k3-universe/react-kit 0.0.29 → 0.0.31
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/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1023 -25
- package/dist/kit/builder/auth/components/Can.d.ts +13 -0
- package/dist/kit/builder/auth/components/Can.d.ts.map +1 -0
- package/dist/kit/builder/auth/components/RequireAuth.d.ts +45 -0
- package/dist/kit/builder/auth/components/RequireAuth.d.ts.map +1 -0
- package/dist/kit/builder/auth/components/ShowWhenAuthenticated.d.ts +8 -0
- package/dist/kit/builder/auth/components/ShowWhenAuthenticated.d.ts.map +1 -0
- package/dist/kit/builder/auth/components/ShowWhenError.d.ts +8 -0
- package/dist/kit/builder/auth/components/ShowWhenError.d.ts.map +1 -0
- package/dist/kit/builder/auth/components/ShowWhenLoading.d.ts +8 -0
- package/dist/kit/builder/auth/components/ShowWhenLoading.d.ts.map +1 -0
- package/dist/kit/builder/auth/components/ShowWhenUnauthenticated.d.ts +8 -0
- package/dist/kit/builder/auth/components/ShowWhenUnauthenticated.d.ts.map +1 -0
- package/dist/kit/builder/auth/components/withPermission.d.ts +7 -0
- package/dist/kit/builder/auth/components/withPermission.d.ts.map +1 -0
- package/dist/kit/builder/auth/hooks/action-hooks.d.ts +18 -0
- package/dist/kit/builder/auth/hooks/action-hooks.d.ts.map +1 -0
- package/dist/kit/builder/auth/hooks/core-hooks.d.ts +56 -0
- package/dist/kit/builder/auth/hooks/core-hooks.d.ts.map +1 -0
- package/dist/kit/builder/auth/hooks/index.d.ts +5 -0
- package/dist/kit/builder/auth/hooks/index.d.ts.map +1 -0
- package/dist/kit/builder/auth/hooks/permission-hooks.d.ts +18 -0
- package/dist/kit/builder/auth/hooks/permission-hooks.d.ts.map +1 -0
- package/dist/kit/builder/auth/hooks/token-hooks.d.ts +13 -0
- package/dist/kit/builder/auth/hooks/token-hooks.d.ts.map +1 -0
- package/dist/kit/builder/auth/index.d.ts +14 -8
- package/dist/kit/builder/auth/index.d.ts.map +1 -1
- package/dist/kit/builder/auth/{AuthProvider.d.ts → providers/AuthProvider.d.ts} +1 -1
- package/dist/kit/builder/auth/providers/AuthProvider.d.ts.map +1 -0
- package/dist/kit/builder/auth/types/adapter-config.d.ts +31 -0
- package/dist/kit/builder/auth/types/adapter-config.d.ts.map +1 -0
- package/dist/kit/builder/auth/types/adapter.d.ts +80 -0
- package/dist/kit/builder/auth/types/adapter.d.ts.map +1 -0
- package/dist/kit/builder/auth/types/core.d.ts +16 -0
- package/dist/kit/builder/auth/types/core.d.ts.map +1 -0
- package/dist/kit/builder/auth/types/index.d.ts +10 -0
- package/dist/kit/builder/auth/types/index.d.ts.map +1 -0
- package/dist/kit/builder/auth/types/middleware.d.ts +11 -0
- package/dist/kit/builder/auth/types/middleware.d.ts.map +1 -0
- package/dist/kit/builder/auth/types/permissions.d.ts +17 -0
- package/dist/kit/builder/auth/types/permissions.d.ts.map +1 -0
- package/dist/kit/builder/auth/types/state.d.ts +13 -0
- package/dist/kit/builder/auth/types/state.d.ts.map +1 -0
- package/dist/kit/builder/auth/types/storage.d.ts +20 -0
- package/dist/kit/builder/auth/types/storage.d.ts.map +1 -0
- package/dist/kit/builder/auth/types/token-manager.d.ts +7 -0
- package/dist/kit/builder/auth/types/token-manager.d.ts.map +1 -0
- package/dist/kit/builder/auth/types/utils.d.ts +7 -0
- package/dist/kit/builder/auth/types/utils.d.ts.map +1 -0
- package/dist/kit/builder/auth/{adapter.d.ts → utils/auth-adapter.d.ts} +2 -2
- package/dist/kit/builder/auth/utils/auth-adapter.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/client-adapters/apollo-link.d.ts +4 -0
- package/dist/kit/builder/auth/utils/client-adapters/apollo-link.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/client-adapters/axios.d.ts +6 -0
- package/dist/kit/builder/auth/utils/client-adapters/axios.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/client-adapters/fetch.d.ts +6 -0
- package/dist/kit/builder/auth/utils/client-adapters/fetch.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/client-adapters/graphql.d.ts +9 -0
- package/dist/kit/builder/auth/utils/client-adapters/graphql.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/client-adapters/index.d.ts +7 -0
- package/dist/kit/builder/auth/utils/client-adapters/index.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/client-adapters/rest.d.ts +9 -0
- package/dist/kit/builder/auth/utils/client-adapters/rest.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/client-adapters/urql-exchange.d.ts +14 -0
- package/dist/kit/builder/auth/utils/client-adapters/urql-exchange.d.ts.map +1 -0
- package/dist/kit/builder/auth/{permission-checker.d.ts → utils/permission-checker.d.ts} +1 -1
- package/dist/kit/builder/auth/utils/permission-checker.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/storage/browser.d.ts +11 -0
- package/dist/kit/builder/auth/utils/storage/browser.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/storage/cookie.d.ts +3 -0
- package/dist/kit/builder/auth/utils/storage/cookie.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/storage/encryption.d.ts +7 -0
- package/dist/kit/builder/auth/utils/storage/encryption.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/storage/env.d.ts +2 -0
- package/dist/kit/builder/auth/utils/storage/env.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/storage/factory.d.ts +6 -0
- package/dist/kit/builder/auth/utils/storage/factory.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/storage/index.d.ts +7 -0
- package/dist/kit/builder/auth/utils/storage/index.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/storage/memory.d.ts +3 -0
- package/dist/kit/builder/auth/utils/storage/memory.d.ts.map +1 -0
- package/dist/kit/builder/auth/{token-manager.d.ts → utils/token-manager.d.ts} +1 -1
- package/dist/kit/builder/auth/utils/token-manager.d.ts.map +1 -0
- package/dist/kit/components/login/Login.d.ts +2 -1
- package/dist/kit/components/login/Login.d.ts.map +1 -1
- package/dist/kit/layouts/admin/components/AdminLayout.d.ts +2 -1
- package/dist/kit/layouts/admin/components/AdminLayout.d.ts.map +1 -1
- package/dist/kit/themes/clean-slate.css +28 -4
- package/dist/kit/themes/default.css +28 -4
- package/dist/kit/themes/minimal-modern.css +28 -4
- package/dist/kit/themes/spotify.css +28 -4
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/kit/builder/auth/components/Can.tsx +27 -0
- package/src/kit/builder/auth/components/RequireAuth.tsx +78 -0
- package/src/kit/builder/auth/components/ShowWhenAuthenticated.tsx +10 -0
- package/src/kit/builder/auth/components/ShowWhenError.tsx +10 -0
- package/src/kit/builder/auth/components/ShowWhenLoading.tsx +10 -0
- package/src/kit/builder/auth/components/ShowWhenUnauthenticated.tsx +10 -0
- package/src/kit/builder/auth/components/withPermission.tsx +23 -0
- package/src/kit/builder/auth/hooks/action-hooks.ts +34 -0
- package/src/kit/builder/auth/hooks/core-hooks.ts +65 -0
- package/src/kit/builder/auth/hooks/index.ts +4 -0
- package/src/kit/builder/auth/hooks/permission-hooks.ts +43 -0
- package/src/kit/builder/auth/hooks/token-hooks.ts +25 -0
- package/src/kit/builder/auth/index.ts +16 -18
- package/src/kit/builder/auth/{AuthProvider.tsx → providers/AuthProvider.tsx} +1 -1
- package/src/kit/builder/auth/types/adapter-config.ts +44 -0
- package/src/kit/builder/auth/types/adapter.ts +132 -0
- package/src/kit/builder/auth/types/core.ts +27 -0
- package/src/kit/builder/auth/types/index.ts +9 -0
- package/src/kit/builder/auth/types/middleware.ts +20 -0
- package/src/kit/builder/auth/types/permissions.ts +23 -0
- package/src/kit/builder/auth/types/state.ts +16 -0
- package/src/kit/builder/auth/types/storage.ts +21 -0
- package/src/kit/builder/auth/types/token-manager.ts +9 -0
- package/src/kit/builder/auth/types/utils.ts +55 -0
- package/src/kit/builder/auth/{adapter.ts → utils/auth-adapter.ts} +3 -2
- package/src/kit/builder/auth/utils/client-adapters/apollo-link.ts +30 -0
- package/src/kit/builder/auth/utils/client-adapters/axios.ts +61 -0
- package/src/kit/builder/auth/utils/client-adapters/fetch.ts +48 -0
- package/src/kit/builder/auth/utils/client-adapters/graphql.ts +60 -0
- package/src/kit/builder/auth/utils/client-adapters/index.ts +6 -0
- package/src/kit/builder/auth/utils/client-adapters/rest.ts +60 -0
- package/src/kit/builder/auth/utils/client-adapters/urql-exchange.ts +76 -0
- package/src/kit/builder/auth/{permission-checker.ts → utils/permission-checker.ts} +1 -1
- package/src/kit/builder/auth/utils/storage/browser.ts +99 -0
- package/src/kit/builder/auth/utils/storage/cookie.ts +116 -0
- package/src/kit/builder/auth/utils/storage/encryption.ts +80 -0
- package/src/kit/builder/auth/utils/storage/env.ts +2 -0
- package/src/kit/builder/auth/utils/storage/factory.ts +37 -0
- package/src/kit/builder/auth/utils/storage/index.ts +6 -0
- package/src/kit/builder/auth/utils/storage/memory.ts +15 -0
- package/src/kit/builder/auth/{token-manager.ts → utils/token-manager.ts} +1 -1
- package/src/kit/components/login/Login.tsx +36 -21
- package/src/kit/layouts/admin/components/AdminLayout.tsx +24 -17
- package/dist/kit/builder/auth/AuthProvider.d.ts.map +0 -1
- package/dist/kit/builder/auth/adapter.d.ts.map +0 -1
- package/dist/kit/builder/auth/client-adapters.d.ts +0 -149
- package/dist/kit/builder/auth/client-adapters.d.ts.map +0 -1
- package/dist/kit/builder/auth/components.d.ts +0 -119
- package/dist/kit/builder/auth/components.d.ts.map +0 -1
- package/dist/kit/builder/auth/hooks.d.ts +0 -158
- package/dist/kit/builder/auth/hooks.d.ts.map +0 -1
- package/dist/kit/builder/auth/permission-checker.d.ts.map +0 -1
- package/dist/kit/builder/auth/storage.d.ts +0 -17
- package/dist/kit/builder/auth/storage.d.ts.map +0 -1
- package/dist/kit/builder/auth/token-manager.d.ts.map +0 -1
- package/dist/kit/builder/auth/types.d.ts +0 -183
- package/dist/kit/builder/auth/types.d.ts.map +0 -1
- package/src/kit/builder/auth/client-adapters.ts +0 -398
- package/src/kit/builder/auth/components.tsx +0 -221
- package/src/kit/builder/auth/hooks.ts +0 -237
- package/src/kit/builder/auth/storage.ts +0 -366
- package/src/kit/builder/auth/types.ts +0 -393
package/dist/index.js
CHANGED
|
@@ -1,9 +1,952 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1
4
|
import { jsx, Fragment, jsxs } from "react/jsx-runtime";
|
|
2
5
|
import * as React from "react";
|
|
3
|
-
import React__default, { forwardRef, createElement, Fragment as Fragment$1, memo as memo$1, useRef, useCallback,
|
|
6
|
+
import React__default, { createContext, useSyncExternalStore, useEffect, useMemo, useContext, forwardRef, createElement, Fragment as Fragment$1, memo as memo$1, useRef, useCallback, useLayoutEffect, useReducer, cloneElement, Component, useState, useImperativeHandle, use, isValidElement, PureComponent } from "react";
|
|
4
7
|
import * as ReactDOM from "react-dom";
|
|
5
8
|
import ReactDOM__default from "react-dom";
|
|
6
9
|
import { useLocation, Link as Link$1 } from "@tanstack/react-router";
|
|
10
|
+
const isBrowser = typeof window !== "undefined" && typeof window.localStorage !== "undefined";
|
|
11
|
+
class SimpleEncryption {
|
|
12
|
+
constructor(key) {
|
|
13
|
+
__publicField(this, "key");
|
|
14
|
+
this.key = key;
|
|
15
|
+
}
|
|
16
|
+
async encrypt(text2) {
|
|
17
|
+
if (!(crypto == null ? void 0 : crypto.subtle)) {
|
|
18
|
+
console.warn("[auth2][storage] Crypto API not available, storing unencrypted");
|
|
19
|
+
return text2;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const encoder = new TextEncoder();
|
|
23
|
+
const data = encoder.encode(text2);
|
|
24
|
+
const keyData = encoder.encode(this.key.padEnd(32, "0").slice(0, 32));
|
|
25
|
+
const cryptoKey = await crypto.subtle.importKey(
|
|
26
|
+
"raw",
|
|
27
|
+
keyData,
|
|
28
|
+
{ name: "AES-GCM", length: 256 },
|
|
29
|
+
false,
|
|
30
|
+
["encrypt"]
|
|
31
|
+
);
|
|
32
|
+
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
33
|
+
const encrypted = await crypto.subtle.encrypt(
|
|
34
|
+
{ name: "AES-GCM", iv },
|
|
35
|
+
cryptoKey,
|
|
36
|
+
data
|
|
37
|
+
);
|
|
38
|
+
const result = new Uint8Array(iv.length + encrypted.byteLength);
|
|
39
|
+
result.set(iv, 0);
|
|
40
|
+
result.set(new Uint8Array(encrypted), iv.length);
|
|
41
|
+
return btoa(String.fromCharCode(...result));
|
|
42
|
+
} catch (error) {
|
|
43
|
+
console.error("[auth2][storage] Encryption failed:", error);
|
|
44
|
+
return text2;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async decrypt(encrypted) {
|
|
48
|
+
if (!(crypto == null ? void 0 : crypto.subtle)) {
|
|
49
|
+
console.warn("[auth2][storage] Crypto API not available, reading unencrypted");
|
|
50
|
+
return encrypted;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
const encoder = new TextEncoder();
|
|
54
|
+
const decoder = new TextDecoder();
|
|
55
|
+
const keyData = encoder.encode(this.key.padEnd(32, "0").slice(0, 32));
|
|
56
|
+
const cryptoKey = await crypto.subtle.importKey(
|
|
57
|
+
"raw",
|
|
58
|
+
keyData,
|
|
59
|
+
{ name: "AES-GCM", length: 256 },
|
|
60
|
+
false,
|
|
61
|
+
["decrypt"]
|
|
62
|
+
);
|
|
63
|
+
const data = Uint8Array.from(atob(encrypted), (c2) => c2.charCodeAt(0));
|
|
64
|
+
const iv = data.slice(0, 12);
|
|
65
|
+
const encryptedData = data.slice(12);
|
|
66
|
+
const decrypted = await crypto.subtle.decrypt(
|
|
67
|
+
{ name: "AES-GCM", iv },
|
|
68
|
+
cryptoKey,
|
|
69
|
+
encryptedData
|
|
70
|
+
);
|
|
71
|
+
return decoder.decode(decrypted);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.error("[auth2][storage] Decryption failed:", error);
|
|
74
|
+
return encrypted;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const createMemoryStorage = () => {
|
|
79
|
+
let value = null;
|
|
80
|
+
return {
|
|
81
|
+
get: () => value,
|
|
82
|
+
set: (next) => {
|
|
83
|
+
value = next;
|
|
84
|
+
},
|
|
85
|
+
clear: () => {
|
|
86
|
+
value = null;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
const createCookieStorage = (options) => {
|
|
91
|
+
var _a;
|
|
92
|
+
const key = options.key ?? "auth2_session";
|
|
93
|
+
const cookieOpts = options.cookieOptions ?? {};
|
|
94
|
+
const fallback = createMemoryStorage();
|
|
95
|
+
const encryption = options.encrypt && options.encryptionKey ? new SimpleEncryption(options.encryptionKey) : null;
|
|
96
|
+
const cookieSetter = typeof Document !== "undefined" ? (_a = Object.getOwnPropertyDescriptor(Document.prototype, "cookie")) == null ? void 0 : _a.set : void 0;
|
|
97
|
+
const assignCookie = (value) => {
|
|
98
|
+
if (!isBrowser || typeof document === "undefined") return;
|
|
99
|
+
if (cookieSetter) {
|
|
100
|
+
cookieSetter.call(document, value);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
Reflect.set(document, "cookie", value);
|
|
104
|
+
};
|
|
105
|
+
const serialize = async (value) => {
|
|
106
|
+
if (value === null) return null;
|
|
107
|
+
const json = JSON.stringify(value);
|
|
108
|
+
return encryption ? await encryption.encrypt(json) : json;
|
|
109
|
+
};
|
|
110
|
+
const deserialize = async (value) => {
|
|
111
|
+
if (!value) return null;
|
|
112
|
+
try {
|
|
113
|
+
const decrypted = encryption ? await encryption.decrypt(value) : value;
|
|
114
|
+
return JSON.parse(decrypted);
|
|
115
|
+
} catch {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const getCookie = (name) => {
|
|
120
|
+
if (!isBrowser) return null;
|
|
121
|
+
const matches = document.cookie.match(
|
|
122
|
+
new RegExp(
|
|
123
|
+
`(?:^|; )${name.replace(/([.$?*|{}()\[\]\\/+^])/g, "\\$1")}=([^;]*)`
|
|
124
|
+
)
|
|
125
|
+
);
|
|
126
|
+
return matches ? decodeURIComponent(matches[1]) : null;
|
|
127
|
+
};
|
|
128
|
+
const setCookie = (name, value, opts = {}) => {
|
|
129
|
+
if (!isBrowser) return;
|
|
130
|
+
let cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}`;
|
|
131
|
+
if (opts.maxAge) cookie += `; max-age=${opts.maxAge}`;
|
|
132
|
+
if (opts.domain) cookie += `; domain=${opts.domain}`;
|
|
133
|
+
if (opts.path !== void 0) cookie += `; path=${opts.path}`;
|
|
134
|
+
else cookie += "; path=/";
|
|
135
|
+
if (opts.secure) cookie += "; secure";
|
|
136
|
+
if (opts.sameSite) cookie += `; samesite=${opts.sameSite}`;
|
|
137
|
+
assignCookie(cookie);
|
|
138
|
+
};
|
|
139
|
+
const deleteCookie = (name) => {
|
|
140
|
+
if (!isBrowser) return;
|
|
141
|
+
assignCookie(`${name}=; max-age=0; path=/`);
|
|
142
|
+
};
|
|
143
|
+
return {
|
|
144
|
+
get: async () => {
|
|
145
|
+
try {
|
|
146
|
+
const raw = getCookie(key);
|
|
147
|
+
const value = await deserialize(raw);
|
|
148
|
+
fallback.set(value);
|
|
149
|
+
return value;
|
|
150
|
+
} catch (error) {
|
|
151
|
+
console.warn("[auth2][storage] Failed to read from cookie", error);
|
|
152
|
+
return fallback.get();
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
set: async (value) => {
|
|
156
|
+
try {
|
|
157
|
+
const serialized = await serialize(value);
|
|
158
|
+
if (serialized === null) {
|
|
159
|
+
deleteCookie(key);
|
|
160
|
+
} else {
|
|
161
|
+
setCookie(key, serialized, cookieOpts);
|
|
162
|
+
}
|
|
163
|
+
fallback.set(value);
|
|
164
|
+
} catch (error) {
|
|
165
|
+
console.warn("[auth2][storage] Failed to write to cookie", error);
|
|
166
|
+
fallback.set(value);
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
clear: () => {
|
|
170
|
+
try {
|
|
171
|
+
deleteCookie(key);
|
|
172
|
+
} catch (error) {
|
|
173
|
+
console.warn("[auth2][storage] Failed to clear cookie", error);
|
|
174
|
+
} finally {
|
|
175
|
+
fallback.clear();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
const createBrowserStorage = (options) => {
|
|
181
|
+
const fallback = createMemoryStorage();
|
|
182
|
+
const targetStorage = options.storage ?? (isBrowser ? window.localStorage : void 0);
|
|
183
|
+
const encryption = options.encrypt && options.encryptionKey ? new SimpleEncryption(options.encryptionKey) : null;
|
|
184
|
+
const defaultSerialize = async (value) => {
|
|
185
|
+
if (value === null) return null;
|
|
186
|
+
const json = JSON.stringify(value);
|
|
187
|
+
return encryption ? await encryption.encrypt(json) : json;
|
|
188
|
+
};
|
|
189
|
+
const defaultDeserialize = async (value) => {
|
|
190
|
+
if (!value) return null;
|
|
191
|
+
try {
|
|
192
|
+
const decrypted = encryption ? await encryption.decrypt(value) : value;
|
|
193
|
+
return JSON.parse(decrypted);
|
|
194
|
+
} catch {
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
const serialize = options.serialize ? async (value) => {
|
|
199
|
+
var _a;
|
|
200
|
+
const result = await ((_a = options.serialize) == null ? void 0 : _a.call(options, value));
|
|
201
|
+
return result ?? null;
|
|
202
|
+
} : defaultSerialize;
|
|
203
|
+
const deserialize = options.deserialize ? async (value) => {
|
|
204
|
+
var _a;
|
|
205
|
+
const result = await ((_a = options.deserialize) == null ? void 0 : _a.call(options, value));
|
|
206
|
+
return result ?? null;
|
|
207
|
+
} : defaultDeserialize;
|
|
208
|
+
if (!targetStorage) {
|
|
209
|
+
return fallback;
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
get: async () => {
|
|
213
|
+
try {
|
|
214
|
+
const raw = targetStorage.getItem(options.key);
|
|
215
|
+
const value = await deserialize(raw);
|
|
216
|
+
fallback.set(value);
|
|
217
|
+
return value;
|
|
218
|
+
} catch (error) {
|
|
219
|
+
console.warn("[auth2][storage] Failed to read from storage", error);
|
|
220
|
+
return fallback.get();
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
set: async (value) => {
|
|
224
|
+
try {
|
|
225
|
+
const serialized = await serialize(value);
|
|
226
|
+
if (serialized === null) {
|
|
227
|
+
targetStorage.removeItem(options.key);
|
|
228
|
+
} else {
|
|
229
|
+
targetStorage.setItem(options.key, serialized);
|
|
230
|
+
}
|
|
231
|
+
fallback.set(value);
|
|
232
|
+
} catch (error) {
|
|
233
|
+
console.warn("[auth2][storage] Failed to write to storage", error);
|
|
234
|
+
fallback.set(value);
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
clear: () => {
|
|
238
|
+
try {
|
|
239
|
+
targetStorage.removeItem(options.key);
|
|
240
|
+
} catch (error) {
|
|
241
|
+
console.warn("[auth2][storage] Failed to clear storage", error);
|
|
242
|
+
} finally {
|
|
243
|
+
fallback.clear();
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
};
|
|
248
|
+
function createStorage(options = {}) {
|
|
249
|
+
const storageType = options.storage ?? "local";
|
|
250
|
+
const key = options.key ?? "auth2_session";
|
|
251
|
+
switch (storageType) {
|
|
252
|
+
case "cookie":
|
|
253
|
+
return createCookieStorage(options);
|
|
254
|
+
case "session":
|
|
255
|
+
return createBrowserStorage({
|
|
256
|
+
key,
|
|
257
|
+
storage: isBrowser ? window.sessionStorage : void 0,
|
|
258
|
+
encrypt: options.encrypt,
|
|
259
|
+
encryptionKey: options.encryptionKey
|
|
260
|
+
});
|
|
261
|
+
case "local":
|
|
262
|
+
return createBrowserStorage({
|
|
263
|
+
key,
|
|
264
|
+
storage: isBrowser ? window.localStorage : void 0,
|
|
265
|
+
encrypt: options.encrypt,
|
|
266
|
+
encryptionKey: options.encryptionKey
|
|
267
|
+
});
|
|
268
|
+
default:
|
|
269
|
+
return createMemoryStorage();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function createTokenManager(config2) {
|
|
273
|
+
const refreshThreshold = (config2 == null ? void 0 : config2.refreshThreshold) ?? 300;
|
|
274
|
+
const isExpired = (expiresAt) => {
|
|
275
|
+
if (!expiresAt) return false;
|
|
276
|
+
return Date.now() >= expiresAt;
|
|
277
|
+
};
|
|
278
|
+
const shouldRefresh = (expiresAt, threshold) => {
|
|
279
|
+
if (!expiresAt) return false;
|
|
280
|
+
const thresholdMs = (threshold ?? refreshThreshold) * 1e3;
|
|
281
|
+
return Date.now() >= expiresAt - thresholdMs;
|
|
282
|
+
};
|
|
283
|
+
const getTimeUntilExpiry = (expiresAt) => {
|
|
284
|
+
if (!expiresAt) return Infinity;
|
|
285
|
+
const timeLeft = expiresAt - Date.now();
|
|
286
|
+
return Math.max(0, timeLeft);
|
|
287
|
+
};
|
|
288
|
+
const scheduleRefresh = (callback, expiresAt) => {
|
|
289
|
+
if (!expiresAt) return () => {
|
|
290
|
+
};
|
|
291
|
+
const timeUntilRefresh = expiresAt - Date.now() - refreshThreshold * 1e3;
|
|
292
|
+
if (timeUntilRefresh <= 0) {
|
|
293
|
+
callback();
|
|
294
|
+
return () => {
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
const timeoutId = setTimeout(callback, timeUntilRefresh);
|
|
298
|
+
return () => clearTimeout(timeoutId);
|
|
299
|
+
};
|
|
300
|
+
return {
|
|
301
|
+
isExpired,
|
|
302
|
+
shouldRefresh,
|
|
303
|
+
getTimeUntilExpiry,
|
|
304
|
+
scheduleRefresh
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
function expandPermissions(permissions, hierarchy) {
|
|
308
|
+
if (!hierarchy) return permissions;
|
|
309
|
+
const expanded = new Set(permissions);
|
|
310
|
+
const queue = [...permissions];
|
|
311
|
+
while (queue.length > 0) {
|
|
312
|
+
const current = queue.shift();
|
|
313
|
+
if (!current) continue;
|
|
314
|
+
const children = hierarchy[current];
|
|
315
|
+
if (children) {
|
|
316
|
+
for (const child of children) {
|
|
317
|
+
if (!expanded.has(child)) {
|
|
318
|
+
expanded.add(child);
|
|
319
|
+
queue.push(child);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return Array.from(expanded);
|
|
325
|
+
}
|
|
326
|
+
function expandRoles(roles, hierarchy) {
|
|
327
|
+
if (!hierarchy) return roles;
|
|
328
|
+
const expanded = new Set(roles);
|
|
329
|
+
const queue = [...roles];
|
|
330
|
+
while (queue.length > 0) {
|
|
331
|
+
const current = queue.shift();
|
|
332
|
+
if (!current) continue;
|
|
333
|
+
const children = hierarchy[current];
|
|
334
|
+
if (children) {
|
|
335
|
+
for (const child of children) {
|
|
336
|
+
if (!expanded.has(child)) {
|
|
337
|
+
expanded.add(child);
|
|
338
|
+
queue.push(child);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return Array.from(expanded);
|
|
344
|
+
}
|
|
345
|
+
function checkPermissions(userPermissions, target, options) {
|
|
346
|
+
if (typeof target === "object" && "permissions" in target) {
|
|
347
|
+
const policy = target;
|
|
348
|
+
const operator = policy.operator ?? "AND";
|
|
349
|
+
if (operator === "AND") {
|
|
350
|
+
return policy.permissions.every((p2) => userPermissions.includes(p2));
|
|
351
|
+
} else {
|
|
352
|
+
return policy.permissions.some((p2) => userPermissions.includes(p2));
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
const targets = Array.isArray(target) ? target : [target];
|
|
356
|
+
const requireAll = (options == null ? void 0 : options.requireAll) ?? true;
|
|
357
|
+
if (targets.length === 0) return true;
|
|
358
|
+
return requireAll ? targets.every((p2) => userPermissions.includes(p2)) : targets.some((p2) => userPermissions.includes(p2));
|
|
359
|
+
}
|
|
360
|
+
function checkRoles(userRoles, target, options) {
|
|
361
|
+
const targets = Array.isArray(target) ? target : [target];
|
|
362
|
+
const requireAll = (options == null ? void 0 : options.requireAll) ?? true;
|
|
363
|
+
if (targets.length === 0) return true;
|
|
364
|
+
return requireAll ? targets.every((r2) => userRoles.includes(r2)) : targets.some((r2) => userRoles.includes(r2));
|
|
365
|
+
}
|
|
366
|
+
function evaluatePermissionRule(userRoles, userPermissions, rule) {
|
|
367
|
+
if (!rule.roles && !rule.permissions) {
|
|
368
|
+
return true;
|
|
369
|
+
}
|
|
370
|
+
const requireAll = rule.requireAll ?? true;
|
|
371
|
+
const roleAllowed = rule.roles ? checkRoles(userRoles, rule.roles, { requireAll }) : true;
|
|
372
|
+
const permissionAllowed = rule.permissions ? checkPermissions(userPermissions, rule.permissions, { requireAll }) : true;
|
|
373
|
+
return requireAll ? roleAllowed && permissionAllowed : roleAllowed || permissionAllowed;
|
|
374
|
+
}
|
|
375
|
+
const unique$1 = (values) => {
|
|
376
|
+
return Array.from(new Set(values));
|
|
377
|
+
};
|
|
378
|
+
function createAuthAdapter(config2) {
|
|
379
|
+
const storage = config2.storage ?? createMemoryStorage();
|
|
380
|
+
const tokenManager = config2.tokenManager ?? createTokenManager({
|
|
381
|
+
refreshThreshold: config2.refreshThreshold ?? 300
|
|
382
|
+
});
|
|
383
|
+
const subscribers = /* @__PURE__ */ new Set();
|
|
384
|
+
const resolveUser = config2.resolveUser ?? ((session) => (session == null ? void 0 : session.user) ?? null);
|
|
385
|
+
const resolveRoles = config2.resolveRoles ?? ((session) => {
|
|
386
|
+
var _a;
|
|
387
|
+
return ((_a = session == null ? void 0 : session.roles) == null ? void 0 : _a.filter((role) => role != null)) ?? [];
|
|
388
|
+
});
|
|
389
|
+
const resolvePermissions = config2.resolvePermissions ?? ((session) => {
|
|
390
|
+
var _a;
|
|
391
|
+
return ((_a = session == null ? void 0 : session.permissions) == null ? void 0 : _a.filter(
|
|
392
|
+
(permission) => permission != null
|
|
393
|
+
)) ?? [];
|
|
394
|
+
});
|
|
395
|
+
let state = {
|
|
396
|
+
status: "idle",
|
|
397
|
+
session: null,
|
|
398
|
+
user: null,
|
|
399
|
+
roles: [],
|
|
400
|
+
permissions: []
|
|
401
|
+
};
|
|
402
|
+
let autoRefreshCleanup = null;
|
|
403
|
+
const executeMiddleware = async (hook, ...args) => {
|
|
404
|
+
if (!config2.middleware) return;
|
|
405
|
+
for (const middleware of config2.middleware) {
|
|
406
|
+
const fn = middleware[hook];
|
|
407
|
+
if (fn) {
|
|
408
|
+
try {
|
|
409
|
+
await fn(...args);
|
|
410
|
+
} catch (error) {
|
|
411
|
+
console.error(`[auth2] Middleware error in ${String(hook)}:`, error);
|
|
412
|
+
if (middleware.onError) {
|
|
413
|
+
await middleware.onError(error);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
const notify = () => {
|
|
420
|
+
var _a;
|
|
421
|
+
for (const listener of subscribers) listener(state);
|
|
422
|
+
(_a = config2.onStateChange) == null ? void 0 : _a.call(config2, state);
|
|
423
|
+
};
|
|
424
|
+
const setState = (next) => {
|
|
425
|
+
state = next;
|
|
426
|
+
notify();
|
|
427
|
+
};
|
|
428
|
+
const computeState = (session, status, error) => {
|
|
429
|
+
const user = resolveUser(session);
|
|
430
|
+
const baseRoles = resolveRoles(session);
|
|
431
|
+
const basePermissions = resolvePermissions(session);
|
|
432
|
+
const roles = unique$1(expandRoles(baseRoles, config2.roleHierarchy));
|
|
433
|
+
const permissions = unique$1(
|
|
434
|
+
expandPermissions(basePermissions, config2.permissionHierarchy)
|
|
435
|
+
);
|
|
436
|
+
const tokenExpiresIn = (session == null ? void 0 : session.expiresAt) ? tokenManager.getTimeUntilExpiry(session.expiresAt) : void 0;
|
|
437
|
+
return {
|
|
438
|
+
status,
|
|
439
|
+
session,
|
|
440
|
+
user,
|
|
441
|
+
roles,
|
|
442
|
+
permissions,
|
|
443
|
+
error,
|
|
444
|
+
lastRefresh: Date.now(),
|
|
445
|
+
tokenExpiresIn
|
|
446
|
+
};
|
|
447
|
+
};
|
|
448
|
+
const readStorage = async () => {
|
|
449
|
+
const stored = await Promise.resolve(storage.get());
|
|
450
|
+
return stored ?? null;
|
|
451
|
+
};
|
|
452
|
+
const writeStorage = async (next) => {
|
|
453
|
+
if (next === null) {
|
|
454
|
+
await Promise.resolve(storage.clear());
|
|
455
|
+
} else {
|
|
456
|
+
await Promise.resolve(storage.set(next));
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
const setupAutoRefresh = () => {
|
|
460
|
+
var _a;
|
|
461
|
+
if (autoRefreshCleanup) {
|
|
462
|
+
autoRefreshCleanup();
|
|
463
|
+
autoRefreshCleanup = null;
|
|
464
|
+
}
|
|
465
|
+
if (!config2.autoRefresh || !config2.refresh || !((_a = state.session) == null ? void 0 : _a.expiresAt)) {
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
if (tokenManager.scheduleRefresh) {
|
|
469
|
+
autoRefreshCleanup = tokenManager.scheduleRefresh(() => {
|
|
470
|
+
refresh().catch((error) => {
|
|
471
|
+
console.error("[auth2] Auto-refresh failed:", error);
|
|
472
|
+
});
|
|
473
|
+
}, state.session.expiresAt);
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
const setSession = async (session, statusOverride, error) => {
|
|
477
|
+
await writeStorage(session);
|
|
478
|
+
const status = statusOverride ?? (session ? "authenticated" : "unauthenticated");
|
|
479
|
+
const nextState = computeState(session, status, error);
|
|
480
|
+
setState(nextState);
|
|
481
|
+
setupAutoRefresh();
|
|
482
|
+
return nextState;
|
|
483
|
+
};
|
|
484
|
+
const sync = async () => {
|
|
485
|
+
var _a;
|
|
486
|
+
setState({ ...state, status: "loading" });
|
|
487
|
+
try {
|
|
488
|
+
const session = await ((_a = config2.loadSession) == null ? void 0 : _a.call(config2)) ?? await readStorage() ?? null;
|
|
489
|
+
if ((session == null ? void 0 : session.expiresAt) && tokenManager.isExpired(session.expiresAt)) {
|
|
490
|
+
if (config2.refresh && session.refreshToken) {
|
|
491
|
+
try {
|
|
492
|
+
const refreshed = await config2.refresh(session);
|
|
493
|
+
return await setSession(refreshed, "authenticated");
|
|
494
|
+
} catch {
|
|
495
|
+
await executeMiddleware("onSessionExpired");
|
|
496
|
+
return await setSession(null, "unauthenticated");
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
await executeMiddleware("onSessionExpired");
|
|
500
|
+
return await setSession(null, "unauthenticated");
|
|
501
|
+
}
|
|
502
|
+
return await setSession(
|
|
503
|
+
session,
|
|
504
|
+
session ? "authenticated" : "unauthenticated"
|
|
505
|
+
);
|
|
506
|
+
} catch (error) {
|
|
507
|
+
await executeMiddleware("onError", error);
|
|
508
|
+
return await setSession(null, "error", error);
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
const withRetry = async (fn, context) => {
|
|
512
|
+
var _a, _b, _c;
|
|
513
|
+
const maxRetries = ((_a = config2.retryConfig) == null ? void 0 : _a.maxRetries) ?? 0;
|
|
514
|
+
const retryDelay = ((_b = config2.retryConfig) == null ? void 0 : _b.retryDelay) ?? 1e3;
|
|
515
|
+
const shouldRetry = (_c = config2.retryConfig) == null ? void 0 : _c.retryOn;
|
|
516
|
+
let lastError;
|
|
517
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
518
|
+
try {
|
|
519
|
+
return await fn();
|
|
520
|
+
} catch (error) {
|
|
521
|
+
lastError = error;
|
|
522
|
+
const isLastAttempt = attempt === maxRetries;
|
|
523
|
+
const shouldRetryError = shouldRetry ? shouldRetry(error) : false;
|
|
524
|
+
if (isLastAttempt || !shouldRetryError) {
|
|
525
|
+
throw error;
|
|
526
|
+
}
|
|
527
|
+
console.warn(
|
|
528
|
+
`[auth2] ${context} failed (attempt ${attempt + 1}/${maxRetries + 1}), retrying...`
|
|
529
|
+
);
|
|
530
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
throw lastError;
|
|
534
|
+
};
|
|
535
|
+
const refresh = async () => {
|
|
536
|
+
const refreshFn = config2.refresh;
|
|
537
|
+
const currentSession = state.session;
|
|
538
|
+
if (!refreshFn) return state;
|
|
539
|
+
if (!currentSession) return state;
|
|
540
|
+
try {
|
|
541
|
+
const refreshed = await withRetry(
|
|
542
|
+
() => refreshFn(currentSession),
|
|
543
|
+
"refresh"
|
|
544
|
+
);
|
|
545
|
+
const nextState = await setSession(refreshed, "authenticated");
|
|
546
|
+
await executeMiddleware("onRefresh", nextState);
|
|
547
|
+
return nextState;
|
|
548
|
+
} catch (error) {
|
|
549
|
+
await executeMiddleware("onError", error);
|
|
550
|
+
return await setSession(state.session, "error", error);
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
const login = async (credentials) => {
|
|
554
|
+
const loginFn = config2.login;
|
|
555
|
+
if (!loginFn) throw new Error("Auth adapter login is not configured");
|
|
556
|
+
setState({ ...state, status: "loading" });
|
|
557
|
+
try {
|
|
558
|
+
await executeMiddleware("onBeforeLogin", credentials);
|
|
559
|
+
const session = await withRetry(() => loginFn(credentials), "login");
|
|
560
|
+
const nextState = await setSession(session, "authenticated");
|
|
561
|
+
await executeMiddleware("onAfterLogin", nextState);
|
|
562
|
+
return nextState;
|
|
563
|
+
} catch (error) {
|
|
564
|
+
await executeMiddleware("onError", error);
|
|
565
|
+
await setSession(null, "error", error);
|
|
566
|
+
throw error;
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
const logout = async () => {
|
|
570
|
+
var _a;
|
|
571
|
+
const current = state.session;
|
|
572
|
+
try {
|
|
573
|
+
await executeMiddleware("onBeforeLogout");
|
|
574
|
+
await ((_a = config2.logout) == null ? void 0 : _a.call(config2, current ?? null));
|
|
575
|
+
} finally {
|
|
576
|
+
if (autoRefreshCleanup) {
|
|
577
|
+
autoRefreshCleanup();
|
|
578
|
+
autoRefreshCleanup = null;
|
|
579
|
+
}
|
|
580
|
+
await setSession(null, "unauthenticated");
|
|
581
|
+
await executeMiddleware("onAfterLogout");
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
const hasRole = (target, options) => {
|
|
585
|
+
return checkRoles(state.roles, target, options);
|
|
586
|
+
};
|
|
587
|
+
const hasPermission = (target, options) => {
|
|
588
|
+
return checkPermissions(state.permissions, target, options);
|
|
589
|
+
};
|
|
590
|
+
const can = (rule) => {
|
|
591
|
+
return evaluatePermissionRule(state.roles, state.permissions, rule);
|
|
592
|
+
};
|
|
593
|
+
const getToken = () => {
|
|
594
|
+
var _a;
|
|
595
|
+
return ((_a = state.session) == null ? void 0 : _a.accessToken) ?? null;
|
|
596
|
+
};
|
|
597
|
+
const isTokenExpired = () => {
|
|
598
|
+
var _a;
|
|
599
|
+
return tokenManager.isExpired((_a = state.session) == null ? void 0 : _a.expiresAt);
|
|
600
|
+
};
|
|
601
|
+
const getTimeUntilExpiry = () => {
|
|
602
|
+
var _a;
|
|
603
|
+
return tokenManager.getTimeUntilExpiry((_a = state.session) == null ? void 0 : _a.expiresAt);
|
|
604
|
+
};
|
|
605
|
+
const scheduleAutoRefresh = () => {
|
|
606
|
+
setupAutoRefresh();
|
|
607
|
+
return () => {
|
|
608
|
+
if (autoRefreshCleanup) {
|
|
609
|
+
autoRefreshCleanup();
|
|
610
|
+
autoRefreshCleanup = null;
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
};
|
|
614
|
+
const api = {
|
|
615
|
+
getState: () => state,
|
|
616
|
+
subscribe: (listener) => {
|
|
617
|
+
subscribers.add(listener);
|
|
618
|
+
return () => {
|
|
619
|
+
subscribers.delete(listener);
|
|
620
|
+
};
|
|
621
|
+
},
|
|
622
|
+
sync,
|
|
623
|
+
login: config2.login ? login : void 0,
|
|
624
|
+
logout,
|
|
625
|
+
refresh: async () => {
|
|
626
|
+
return await refresh();
|
|
627
|
+
},
|
|
628
|
+
setSession: async (session) => {
|
|
629
|
+
return await setSession(session);
|
|
630
|
+
},
|
|
631
|
+
hasRole,
|
|
632
|
+
hasPermission,
|
|
633
|
+
can,
|
|
634
|
+
getToken,
|
|
635
|
+
isTokenExpired,
|
|
636
|
+
getTimeUntilExpiry,
|
|
637
|
+
scheduleAutoRefresh
|
|
638
|
+
};
|
|
639
|
+
return api;
|
|
640
|
+
}
|
|
641
|
+
const AuthContext = createContext(void 0);
|
|
642
|
+
function AuthProvider({
|
|
643
|
+
adapter,
|
|
644
|
+
children,
|
|
645
|
+
autoSync = true
|
|
646
|
+
}) {
|
|
647
|
+
const state = useSyncExternalStore(
|
|
648
|
+
adapter.subscribe,
|
|
649
|
+
adapter.getState,
|
|
650
|
+
adapter.getState
|
|
651
|
+
);
|
|
652
|
+
useEffect(() => {
|
|
653
|
+
if (!autoSync) return;
|
|
654
|
+
adapter.sync().catch(() => void 0);
|
|
655
|
+
}, [adapter, autoSync]);
|
|
656
|
+
const value = useMemo(() => {
|
|
657
|
+
const login = adapter.login ? async (credentials) => {
|
|
658
|
+
if (!adapter.login) {
|
|
659
|
+
throw new Error("Login is not configured");
|
|
660
|
+
}
|
|
661
|
+
return await adapter.login(credentials);
|
|
662
|
+
} : void 0;
|
|
663
|
+
return {
|
|
664
|
+
state,
|
|
665
|
+
status: state.status,
|
|
666
|
+
session: state.session,
|
|
667
|
+
user: state.user,
|
|
668
|
+
roles: state.roles,
|
|
669
|
+
permissions: state.permissions,
|
|
670
|
+
error: state.error,
|
|
671
|
+
login,
|
|
672
|
+
logout: adapter.logout,
|
|
673
|
+
refresh: adapter.refresh,
|
|
674
|
+
setSession: adapter.setSession,
|
|
675
|
+
hasRole: adapter.hasRole,
|
|
676
|
+
hasPermission: adapter.hasPermission,
|
|
677
|
+
can: adapter.can,
|
|
678
|
+
getToken: adapter.getToken,
|
|
679
|
+
isTokenExpired: adapter.isTokenExpired,
|
|
680
|
+
getTimeUntilExpiry: adapter.getTimeUntilExpiry
|
|
681
|
+
};
|
|
682
|
+
}, [adapter, state]);
|
|
683
|
+
const contextValue = value;
|
|
684
|
+
return /* @__PURE__ */ jsx(AuthContext.Provider, { value: contextValue, children });
|
|
685
|
+
}
|
|
686
|
+
function useAuthContext() {
|
|
687
|
+
const ctx = useContext(AuthContext);
|
|
688
|
+
if (!ctx) throw new Error("useAuthContext must be used within AuthProvider");
|
|
689
|
+
return ctx;
|
|
690
|
+
}
|
|
691
|
+
function createGraphQLAuthAdapter(options) {
|
|
692
|
+
return {
|
|
693
|
+
login: options.client.login,
|
|
694
|
+
logout: options.client.logout,
|
|
695
|
+
refresh: options.client.refresh ? async (session) => {
|
|
696
|
+
if (!session.refreshToken) {
|
|
697
|
+
throw new Error("No refresh token available");
|
|
698
|
+
}
|
|
699
|
+
if (!options.client.refresh) {
|
|
700
|
+
throw new Error("Refresh function not provided");
|
|
701
|
+
}
|
|
702
|
+
return await options.client.refresh(session.refreshToken);
|
|
703
|
+
} : void 0,
|
|
704
|
+
loadSession: options.client.getCurrentUser,
|
|
705
|
+
resolveUser: options.resolveUser,
|
|
706
|
+
resolveRoles: options.resolveRoles,
|
|
707
|
+
resolvePermissions: options.resolvePermissions
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
function createRESTAuthAdapter(options) {
|
|
711
|
+
return {
|
|
712
|
+
login: options.client.login,
|
|
713
|
+
logout: options.client.logout,
|
|
714
|
+
refresh: options.client.refresh ? async (session) => {
|
|
715
|
+
if (!session.refreshToken) {
|
|
716
|
+
throw new Error("No refresh token available");
|
|
717
|
+
}
|
|
718
|
+
if (!options.client.refresh) {
|
|
719
|
+
throw new Error("Refresh function not provided");
|
|
720
|
+
}
|
|
721
|
+
return await options.client.refresh(session.refreshToken);
|
|
722
|
+
} : void 0,
|
|
723
|
+
loadSession: options.client.getCurrentUser,
|
|
724
|
+
resolveUser: options.resolveUser,
|
|
725
|
+
resolveRoles: options.resolveRoles,
|
|
726
|
+
resolvePermissions: options.resolvePermissions
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
function createAxiosAuthInterceptor(axiosInstance, getToken, options) {
|
|
730
|
+
const tokenType = (options == null ? void 0 : options.tokenType) ?? "Bearer";
|
|
731
|
+
axiosInstance.interceptors.request.use(
|
|
732
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
733
|
+
async (config2) => {
|
|
734
|
+
const token = getToken();
|
|
735
|
+
if (token) {
|
|
736
|
+
config2.headers.Authorization = `${tokenType} ${token}`;
|
|
737
|
+
}
|
|
738
|
+
return config2;
|
|
739
|
+
},
|
|
740
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
741
|
+
(error) => Promise.reject(error)
|
|
742
|
+
);
|
|
743
|
+
if (options == null ? void 0 : options.refreshToken) {
|
|
744
|
+
axiosInstance.interceptors.response.use(
|
|
745
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
746
|
+
(response) => response,
|
|
747
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
748
|
+
async (error) => {
|
|
749
|
+
var _a, _b;
|
|
750
|
+
const originalRequest = error.config;
|
|
751
|
+
if (((_a = error.response) == null ? void 0 : _a.status) === 401 && !originalRequest._retry && options.refreshToken) {
|
|
752
|
+
originalRequest._retry = true;
|
|
753
|
+
try {
|
|
754
|
+
await options.refreshToken();
|
|
755
|
+
const token = getToken();
|
|
756
|
+
if (token) {
|
|
757
|
+
originalRequest.headers.Authorization = `${tokenType} ${token}`;
|
|
758
|
+
}
|
|
759
|
+
return axiosInstance(originalRequest);
|
|
760
|
+
} catch (refreshError) {
|
|
761
|
+
(_b = options.onTokenExpired) == null ? void 0 : _b.call(options);
|
|
762
|
+
return Promise.reject(refreshError);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
return Promise.reject(error);
|
|
766
|
+
}
|
|
767
|
+
);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
function createAuthFetch(getToken, options) {
|
|
771
|
+
const tokenType = (options == null ? void 0 : options.tokenType) ?? "Bearer";
|
|
772
|
+
return async (input, init) => {
|
|
773
|
+
var _a;
|
|
774
|
+
const token = getToken();
|
|
775
|
+
const headers = new Headers(init == null ? void 0 : init.headers);
|
|
776
|
+
if (token) {
|
|
777
|
+
headers.set("Authorization", `${tokenType} ${token}`);
|
|
778
|
+
}
|
|
779
|
+
const response = await fetch(input, {
|
|
780
|
+
...init,
|
|
781
|
+
headers
|
|
782
|
+
});
|
|
783
|
+
if (response.status === 401 && (options == null ? void 0 : options.refreshToken)) {
|
|
784
|
+
try {
|
|
785
|
+
await options.refreshToken();
|
|
786
|
+
const newToken = getToken();
|
|
787
|
+
if (newToken) {
|
|
788
|
+
headers.set("Authorization", `${tokenType} ${newToken}`);
|
|
789
|
+
return await fetch(input, {
|
|
790
|
+
...init,
|
|
791
|
+
headers
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
} catch (error) {
|
|
795
|
+
(_a = options.onTokenExpired) == null ? void 0 : _a.call(options);
|
|
796
|
+
throw error;
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
return response;
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
function createApolloAuthLink(getToken, options) {
|
|
803
|
+
const tokenType = (options == null ? void 0 : options.tokenType) ?? "Bearer";
|
|
804
|
+
return (ApolloLink) => {
|
|
805
|
+
return new ApolloLink((operation, forward) => {
|
|
806
|
+
const token = getToken();
|
|
807
|
+
if (token) {
|
|
808
|
+
operation.setContext(({ headers = {} }) => ({
|
|
809
|
+
headers: {
|
|
810
|
+
...headers,
|
|
811
|
+
authorization: `${tokenType} ${token}`
|
|
812
|
+
}
|
|
813
|
+
}));
|
|
814
|
+
}
|
|
815
|
+
return forward(operation);
|
|
816
|
+
});
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
function useAuth() {
|
|
820
|
+
return useAuthContext();
|
|
821
|
+
}
|
|
822
|
+
function useAuthStatus() {
|
|
823
|
+
const { status } = useAuthContext();
|
|
824
|
+
return status;
|
|
825
|
+
}
|
|
826
|
+
function useIsAuthenticated() {
|
|
827
|
+
const { status } = useAuthContext();
|
|
828
|
+
return status === "authenticated";
|
|
829
|
+
}
|
|
830
|
+
function useAuthSession() {
|
|
831
|
+
const { session } = useAuthContext();
|
|
832
|
+
return session;
|
|
833
|
+
}
|
|
834
|
+
function useAuthUser() {
|
|
835
|
+
const { user } = useAuthContext();
|
|
836
|
+
return user;
|
|
837
|
+
}
|
|
838
|
+
function useAuthRoles() {
|
|
839
|
+
const { roles } = useAuthContext();
|
|
840
|
+
return roles;
|
|
841
|
+
}
|
|
842
|
+
function useAuthPermissions() {
|
|
843
|
+
const { permissions } = useAuthContext();
|
|
844
|
+
return permissions;
|
|
845
|
+
}
|
|
846
|
+
function useAuthError() {
|
|
847
|
+
const { error } = useAuthContext();
|
|
848
|
+
return error;
|
|
849
|
+
}
|
|
850
|
+
function usePermission(permission, options) {
|
|
851
|
+
const { hasPermission } = useAuthContext();
|
|
852
|
+
return hasPermission(permission, options);
|
|
853
|
+
}
|
|
854
|
+
function useRole(roles, options) {
|
|
855
|
+
const { hasRole } = useAuthContext();
|
|
856
|
+
return hasRole(roles, options);
|
|
857
|
+
}
|
|
858
|
+
function useCan(rule) {
|
|
859
|
+
const { can } = useAuthContext();
|
|
860
|
+
return can(rule);
|
|
861
|
+
}
|
|
862
|
+
function useAuthToken() {
|
|
863
|
+
const { getToken } = useAuthContext();
|
|
864
|
+
return getToken();
|
|
865
|
+
}
|
|
866
|
+
function useIsTokenExpired() {
|
|
867
|
+
const { isTokenExpired } = useAuthContext();
|
|
868
|
+
return isTokenExpired();
|
|
869
|
+
}
|
|
870
|
+
function useTimeUntilExpiry() {
|
|
871
|
+
const { getTimeUntilExpiry } = useAuthContext();
|
|
872
|
+
return getTimeUntilExpiry();
|
|
873
|
+
}
|
|
874
|
+
function useLogin() {
|
|
875
|
+
const { login } = useAuthContext();
|
|
876
|
+
return login;
|
|
877
|
+
}
|
|
878
|
+
function useLogout() {
|
|
879
|
+
const { logout } = useAuthContext();
|
|
880
|
+
return logout;
|
|
881
|
+
}
|
|
882
|
+
function useRefresh() {
|
|
883
|
+
const { refresh } = useAuthContext();
|
|
884
|
+
return refresh;
|
|
885
|
+
}
|
|
886
|
+
function useSetSession() {
|
|
887
|
+
const { setSession } = useAuthContext();
|
|
888
|
+
return setSession;
|
|
889
|
+
}
|
|
890
|
+
function RequireAuth({
|
|
891
|
+
children,
|
|
892
|
+
fallback = null,
|
|
893
|
+
loadingFallback = null,
|
|
894
|
+
roles,
|
|
895
|
+
permissions,
|
|
896
|
+
requireAll = true
|
|
897
|
+
}) {
|
|
898
|
+
const { status, can } = useAuthContext();
|
|
899
|
+
if (status === "loading" || status === "idle") {
|
|
900
|
+
return loadingFallback;
|
|
901
|
+
}
|
|
902
|
+
if (status !== "authenticated") {
|
|
903
|
+
return fallback;
|
|
904
|
+
}
|
|
905
|
+
if (!roles && !permissions) {
|
|
906
|
+
return children;
|
|
907
|
+
}
|
|
908
|
+
const allowed = can({ roles, permissions, requireAll });
|
|
909
|
+
if (!allowed) {
|
|
910
|
+
return fallback;
|
|
911
|
+
}
|
|
912
|
+
return children;
|
|
913
|
+
}
|
|
914
|
+
function Can({
|
|
915
|
+
children,
|
|
916
|
+
fallback = null,
|
|
917
|
+
roles,
|
|
918
|
+
permissions,
|
|
919
|
+
requireAll = true
|
|
920
|
+
}) {
|
|
921
|
+
const allowed = useCan({ roles, permissions, requireAll });
|
|
922
|
+
if (!allowed) return fallback;
|
|
923
|
+
return children;
|
|
924
|
+
}
|
|
925
|
+
function withPermission(Component2, options) {
|
|
926
|
+
const WithPermissionWrapper = (props2) => {
|
|
927
|
+
const allowed = useCan(options);
|
|
928
|
+
if (!allowed) return null;
|
|
929
|
+
return /* @__PURE__ */ jsx(Component2, { ...props2 });
|
|
930
|
+
};
|
|
931
|
+
WithPermissionWrapper.displayName = `WithPermission(${Component2.displayName ?? Component2.name ?? "Component"})`;
|
|
932
|
+
return WithPermissionWrapper;
|
|
933
|
+
}
|
|
934
|
+
function ShowWhenAuthenticated({ children }) {
|
|
935
|
+
const { status } = useAuthContext();
|
|
936
|
+
return status === "authenticated" ? children : null;
|
|
937
|
+
}
|
|
938
|
+
function ShowWhenUnauthenticated({ children }) {
|
|
939
|
+
const { status } = useAuthContext();
|
|
940
|
+
return status === "unauthenticated" ? children : null;
|
|
941
|
+
}
|
|
942
|
+
function ShowWhenLoading({ children }) {
|
|
943
|
+
const { status } = useAuthContext();
|
|
944
|
+
return status === "loading" ? children : null;
|
|
945
|
+
}
|
|
946
|
+
function ShowWhenError({ children }) {
|
|
947
|
+
const { status } = useAuthContext();
|
|
948
|
+
return status === "error" ? children : null;
|
|
949
|
+
}
|
|
7
950
|
/**
|
|
8
951
|
* table-core
|
|
9
952
|
*
|
|
@@ -216,7 +1159,7 @@ function createHeader(table, column, options) {
|
|
|
216
1159
|
});
|
|
217
1160
|
return header;
|
|
218
1161
|
}
|
|
219
|
-
const Headers = {
|
|
1162
|
+
const Headers$1 = {
|
|
220
1163
|
createTable: (table) => {
|
|
221
1164
|
table.getHeaderGroups = memo(() => [table.getAllColumns(), table.getVisibleLeafColumns(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allColumns, leafColumns, left, right) => {
|
|
222
1165
|
var _left$map$filter, _right$map$filter;
|
|
@@ -2418,7 +3361,7 @@ const RowSorting = {
|
|
|
2418
3361
|
}
|
|
2419
3362
|
};
|
|
2420
3363
|
const builtInFeatures = [
|
|
2421
|
-
Headers,
|
|
3364
|
+
Headers$1,
|
|
2422
3365
|
ColumnVisibility,
|
|
2423
3366
|
ColumnOrdering,
|
|
2424
3367
|
ColumnPinning,
|
|
@@ -38972,7 +39915,7 @@ function requireLodash() {
|
|
|
38972
39915
|
var reIsNative = RegExp2(
|
|
38973
39916
|
"^" + funcToString.call(hasOwnProperty).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$"
|
|
38974
39917
|
);
|
|
38975
|
-
var
|
|
39918
|
+
var Buffer2 = moduleExports ? context.Buffer : undefined$1, Symbol2 = context.Symbol, Uint8Array2 = context.Uint8Array, allocUnsafe = Buffer2 ? Buffer2.allocUnsafe : undefined$1, getPrototype = overArg(Object2.getPrototypeOf, Object2), objectCreate = Object2.create, propertyIsEnumerable = objectProto.propertyIsEnumerable, splice = arrayProto.splice, spreadableSymbol = Symbol2 ? Symbol2.isConcatSpreadable : undefined$1, symIterator = Symbol2 ? Symbol2.iterator : undefined$1, symToStringTag = Symbol2 ? Symbol2.toStringTag : undefined$1;
|
|
38976
39919
|
var defineProperty = (function() {
|
|
38977
39920
|
try {
|
|
38978
39921
|
var func = getNative(Object2, "defineProperty");
|
|
@@ -38982,7 +39925,7 @@ function requireLodash() {
|
|
|
38982
39925
|
}
|
|
38983
39926
|
})();
|
|
38984
39927
|
var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout, ctxNow = Date2 && Date2.now !== root.Date.now && Date2.now, ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
|
|
38985
|
-
var nativeCeil = Math2.ceil, nativeFloor = Math2.floor, nativeGetSymbols = Object2.getOwnPropertySymbols, nativeIsBuffer =
|
|
39928
|
+
var nativeCeil = Math2.ceil, nativeFloor = Math2.floor, nativeGetSymbols = Object2.getOwnPropertySymbols, nativeIsBuffer = Buffer2 ? Buffer2.isBuffer : undefined$1, nativeIsFinite = context.isFinite, nativeJoin = arrayProto.join, nativeKeys = overArg(Object2.keys, Object2), nativeMax = Math2.max, nativeMin = Math2.min, nativeNow = Date2.now, nativeParseInt = context.parseInt, nativeRandom = Math2.random, nativeReverse = arrayProto.reverse;
|
|
38986
39929
|
var DataView = getNative(context, "DataView"), Map2 = getNative(context, "Map"), Promise2 = getNative(context, "Promise"), Set2 = getNative(context, "Set"), WeakMap2 = getNative(context, "WeakMap"), nativeCreate = getNative(Object2, "create");
|
|
38987
39930
|
var metaMap = WeakMap2 && new WeakMap2();
|
|
38988
39931
|
var realNames = {};
|
|
@@ -40274,7 +41217,7 @@ function requireLodash() {
|
|
|
40274
41217
|
}
|
|
40275
41218
|
function cloneArrayBuffer(arrayBuffer) {
|
|
40276
41219
|
var result2 = new arrayBuffer.constructor(arrayBuffer.byteLength);
|
|
40277
|
-
new
|
|
41220
|
+
new Uint8Array2(result2).set(new Uint8Array2(arrayBuffer));
|
|
40278
41221
|
return result2;
|
|
40279
41222
|
}
|
|
40280
41223
|
function cloneDataView(dataView, isDeep) {
|
|
@@ -40878,7 +41821,7 @@ function requireLodash() {
|
|
|
40878
41821
|
object2 = object2.buffer;
|
|
40879
41822
|
other = other.buffer;
|
|
40880
41823
|
case arrayBufferTag:
|
|
40881
|
-
if (object2.byteLength != other.byteLength || !equalFunc(new
|
|
41824
|
+
if (object2.byteLength != other.byteLength || !equalFunc(new Uint8Array2(object2), new Uint8Array2(other))) {
|
|
40882
41825
|
return false;
|
|
40883
41826
|
}
|
|
40884
41827
|
return true;
|
|
@@ -44760,22 +45703,28 @@ function Login({
|
|
|
44760
45703
|
subtitle,
|
|
44761
45704
|
signupLabel = "Don't have an account?",
|
|
44762
45705
|
signupLinkLabel = "Sign up",
|
|
44763
|
-
signupHref
|
|
45706
|
+
signupHref,
|
|
44764
45707
|
forgotPasswordLabel = "Forgot your password?",
|
|
44765
45708
|
forgotPasswordLinkLabel = "Reset Here",
|
|
44766
45709
|
forgotPasswordHref,
|
|
44767
45710
|
rightImageSrc,
|
|
44768
45711
|
rightImageAlt = "Login image",
|
|
45712
|
+
showRightImage = true,
|
|
44769
45713
|
className,
|
|
44770
45714
|
continueWith,
|
|
44771
45715
|
children
|
|
44772
45716
|
}) {
|
|
45717
|
+
const shouldRenderRightColumn = showRightImage;
|
|
44773
45718
|
return /* @__PURE__ */ jsxs(
|
|
44774
45719
|
"div",
|
|
44775
45720
|
{
|
|
44776
|
-
className: [
|
|
45721
|
+
className: [
|
|
45722
|
+
"mx-auto grid min-h-dvh w-full max-w-[1920px] grid-cols-1 lg:min-h-[768px]",
|
|
45723
|
+
shouldRenderRightColumn ? "lg:grid-cols-[minmax(0,_1fr)_minmax(384px,_1fr)]" : null,
|
|
45724
|
+
className
|
|
45725
|
+
].filter(Boolean).join(" "),
|
|
44777
45726
|
children: [
|
|
44778
|
-
/* @__PURE__ */ jsx("div", { className: "flex items-center justify-center p-6
|
|
45727
|
+
/* @__PURE__ */ jsx("div", { className: "flex min-h-0 items-center justify-center p-6 sm:p-8 lg:p-12", children: /* @__PURE__ */ jsxs("div", { className: "w-full max-w-md", children: [
|
|
44779
45728
|
/* @__PURE__ */ jsxs("div", { className: "mb-6 text-center", children: [
|
|
44780
45729
|
/* @__PURE__ */ jsx("h1", { className: "text-2xl font-bold leading-tight tracking-tight", children: appTitle }),
|
|
44781
45730
|
subtitle ? /* @__PURE__ */ jsx("p", { className: "text-muted-foreground mt-1 text-sm", children: subtitle }) : null
|
|
@@ -44799,13 +45748,13 @@ function Login({
|
|
|
44799
45748
|
/* @__PURE__ */ jsx("div", { className: "grid gap-3", children: continueWith })
|
|
44800
45749
|
] }) : null
|
|
44801
45750
|
] }),
|
|
44802
|
-
/* @__PURE__ */ jsxs("div", { className: "mt-6 text-center text-sm", children: [
|
|
45751
|
+
signupHref ? /* @__PURE__ */ jsxs("div", { className: "mt-6 text-center text-sm", children: [
|
|
44803
45752
|
signupLabel,
|
|
44804
45753
|
" ",
|
|
44805
45754
|
/* @__PURE__ */ jsx("a", { href: signupHref, className: "underline underline-offset-4", children: signupLinkLabel })
|
|
44806
|
-
] })
|
|
45755
|
+
] }) : null
|
|
44807
45756
|
] }) }),
|
|
44808
|
-
/* @__PURE__ */ jsx("div", { className: "hidden
|
|
45757
|
+
shouldRenderRightColumn ? /* @__PURE__ */ jsx("div", { className: "hidden max-h-[1280px] lg:block", children: rightImageSrc ? /* @__PURE__ */ jsx(
|
|
44809
45758
|
"img",
|
|
44810
45759
|
{
|
|
44811
45760
|
src: rightImageSrc,
|
|
@@ -44813,7 +45762,7 @@ function Login({
|
|
|
44813
45762
|
className: "h-full w-full object-cover",
|
|
44814
45763
|
loading: "lazy"
|
|
44815
45764
|
}
|
|
44816
|
-
) : /* @__PURE__ */ jsx("div", { className: "h-full w-full bg-muted" }) })
|
|
45765
|
+
) : /* @__PURE__ */ jsx("div", { className: "h-full w-full bg-muted" }) }) : null
|
|
44817
45766
|
]
|
|
44818
45767
|
}
|
|
44819
45768
|
);
|
|
@@ -45935,7 +46884,8 @@ function AdminLayoutContent({
|
|
|
45935
46884
|
sidebarHeaderTitle,
|
|
45936
46885
|
sidebarHeaderIcon,
|
|
45937
46886
|
headerAfterTrigger,
|
|
45938
|
-
headerAfterTheme
|
|
46887
|
+
headerAfterTheme,
|
|
46888
|
+
onLogout
|
|
45939
46889
|
}) {
|
|
45940
46890
|
const { groups: sidebarGroups } = useAdminSidebarMenu();
|
|
45941
46891
|
const location = useLocation();
|
|
@@ -46034,11 +46984,14 @@ function AdminLayoutContent({
|
|
|
46034
46984
|
}
|
|
46035
46985
|
)
|
|
46036
46986
|
] }, group.id)) }),
|
|
46037
|
-
/* @__PURE__ */ jsx(SidebarFooter, { className: "bg-sidebar border-t border-sidebar-border px-2 py-3", children: /* @__PURE__ */ jsx(SidebarMenu, { children: /* @__PURE__ */ jsx(SidebarMenuItem, { className: "group-data-[collapsible=icon]:flex group-data-[collapsible=icon]:w-full group-data-[collapsible=icon]:justify-center", children: /* @__PURE__ */ jsx(
|
|
46987
|
+
onLogout && /* @__PURE__ */ jsx(SidebarFooter, { className: "bg-sidebar border-t border-sidebar-border px-2 py-3", children: /* @__PURE__ */ jsx(SidebarMenu, { children: /* @__PURE__ */ jsx(SidebarMenuItem, { className: "group-data-[collapsible=icon]:flex group-data-[collapsible=icon]:w-full group-data-[collapsible=icon]:justify-center", children: /* @__PURE__ */ jsx(
|
|
46038
46988
|
SidebarMenuButton,
|
|
46039
46989
|
{
|
|
46040
46990
|
tooltip: "Logout",
|
|
46041
|
-
className: "group relative overflow-hidden rounded-lg mx-1 transition-all duration-200 hover:bg-sidebar-accent/70 hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:flex group-data-[collapsible=icon]:w-full group-data-[collapsible=icon]:items-center group-data-[collapsible=icon]:!justify-center group-data-[collapsible=icon]:!px-0 group-data-[collapsible=icon]:!gap-0",
|
|
46991
|
+
className: "cursor-pointer group relative overflow-hidden rounded-lg mx-1 transition-all duration-200 hover:bg-sidebar-accent/70 hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:flex group-data-[collapsible=icon]:w-full group-data-[collapsible=icon]:items-center group-data-[collapsible=icon]:!justify-center group-data-[collapsible=icon]:!px-0 group-data-[collapsible=icon]:!gap-0",
|
|
46992
|
+
onClick: () => {
|
|
46993
|
+
void onLogout();
|
|
46994
|
+
},
|
|
46042
46995
|
children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 px-3 py-2.5 group-data-[collapsible=icon]:w-full group-data-[collapsible=icon]:items-center group-data-[collapsible=icon]:!justify-center group-data-[collapsible=icon]:!gap-0 group-data-[collapsible=icon]:!px-0", children: [
|
|
46043
46996
|
/* @__PURE__ */ jsx(LogOut, { className: "h-4 w-4 text-sidebar-foreground group-hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:mx-auto group-data-[collapsible=icon]:mr-0" }),
|
|
46044
46997
|
/* @__PURE__ */ jsx("span", { className: "font-medium text-sidebar-foreground group-hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:hidden", children: "Logout" })
|
|
@@ -46071,7 +47024,8 @@ function AdminLayout({
|
|
|
46071
47024
|
sidebarHeaderTitle,
|
|
46072
47025
|
sidebarHeaderIcon,
|
|
46073
47026
|
headerAfterTrigger,
|
|
46074
|
-
headerAfterTheme
|
|
47027
|
+
headerAfterTheme,
|
|
47028
|
+
onLogout
|
|
46075
47029
|
}) {
|
|
46076
47030
|
return /* @__PURE__ */ jsx(AdminMenuProvider, { children: /* @__PURE__ */ jsx(SidebarProvider, { children: /* @__PURE__ */ jsx(
|
|
46077
47031
|
AdminLayoutContent,
|
|
@@ -46083,6 +47037,7 @@ function AdminLayout({
|
|
|
46083
47037
|
sidebarHeaderIcon,
|
|
46084
47038
|
headerAfterTrigger,
|
|
46085
47039
|
headerAfterTheme,
|
|
47040
|
+
onLogout,
|
|
46086
47041
|
children
|
|
46087
47042
|
}
|
|
46088
47043
|
) }) });
|
|
@@ -52233,8 +53188,8 @@ function require_Uint8Array() {
|
|
|
52233
53188
|
if (hasRequired_Uint8Array) return _Uint8Array;
|
|
52234
53189
|
hasRequired_Uint8Array = 1;
|
|
52235
53190
|
var root = require_root();
|
|
52236
|
-
var
|
|
52237
|
-
_Uint8Array =
|
|
53191
|
+
var Uint8Array2 = root.Uint8Array;
|
|
53192
|
+
_Uint8Array = Uint8Array2;
|
|
52238
53193
|
return _Uint8Array;
|
|
52239
53194
|
}
|
|
52240
53195
|
var _mapToArray;
|
|
@@ -52272,7 +53227,7 @@ var hasRequired_equalByTag;
|
|
|
52272
53227
|
function require_equalByTag() {
|
|
52273
53228
|
if (hasRequired_equalByTag) return _equalByTag;
|
|
52274
53229
|
hasRequired_equalByTag = 1;
|
|
52275
|
-
var Symbol2 = require_Symbol(),
|
|
53230
|
+
var Symbol2 = require_Symbol(), Uint8Array2 = require_Uint8Array(), eq = requireEq(), equalArrays = require_equalArrays(), mapToArray = require_mapToArray(), setToArray = require_setToArray();
|
|
52276
53231
|
var COMPARE_PARTIAL_FLAG = 1, COMPARE_UNORDERED_FLAG = 2;
|
|
52277
53232
|
var boolTag = "[object Boolean]", dateTag = "[object Date]", errorTag = "[object Error]", mapTag = "[object Map]", numberTag = "[object Number]", regexpTag = "[object RegExp]", setTag = "[object Set]", stringTag = "[object String]", symbolTag = "[object Symbol]";
|
|
52278
53233
|
var arrayBufferTag = "[object ArrayBuffer]", dataViewTag = "[object DataView]";
|
|
@@ -52286,7 +53241,7 @@ function require_equalByTag() {
|
|
|
52286
53241
|
object2 = object2.buffer;
|
|
52287
53242
|
other = other.buffer;
|
|
52288
53243
|
case arrayBufferTag:
|
|
52289
|
-
if (object2.byteLength != other.byteLength || !equalFunc(new
|
|
53244
|
+
if (object2.byteLength != other.byteLength || !equalFunc(new Uint8Array2(object2), new Uint8Array2(other))) {
|
|
52290
53245
|
return false;
|
|
52291
53246
|
}
|
|
52292
53247
|
return true;
|
|
@@ -52471,8 +53426,8 @@ function requireIsBuffer() {
|
|
|
52471
53426
|
var freeExports = exports && !exports.nodeType && exports;
|
|
52472
53427
|
var freeModule = freeExports && true && module && !module.nodeType && module;
|
|
52473
53428
|
var moduleExports = freeModule && freeModule.exports === freeExports;
|
|
52474
|
-
var
|
|
52475
|
-
var nativeIsBuffer =
|
|
53429
|
+
var Buffer2 = moduleExports ? root.Buffer : void 0;
|
|
53430
|
+
var nativeIsBuffer = Buffer2 ? Buffer2.isBuffer : void 0;
|
|
52476
53431
|
var isBuffer2 = nativeIsBuffer || stubFalse;
|
|
52477
53432
|
module.exports = isBuffer2;
|
|
52478
53433
|
})(isBuffer, isBuffer.exports);
|
|
@@ -64062,6 +65017,7 @@ export {
|
|
|
64062
65017
|
AlertDialogTrigger,
|
|
64063
65018
|
AlertTitle,
|
|
64064
65019
|
AspectRatio,
|
|
65020
|
+
AuthProvider,
|
|
64065
65021
|
Autocomplete,
|
|
64066
65022
|
Avatar,
|
|
64067
65023
|
AvatarFallback,
|
|
@@ -64077,6 +65033,7 @@ export {
|
|
|
64077
65033
|
Button$1 as Button,
|
|
64078
65034
|
Calendar,
|
|
64079
65035
|
CalendarDayButton,
|
|
65036
|
+
Can,
|
|
64080
65037
|
Card,
|
|
64081
65038
|
CardAction,
|
|
64082
65039
|
CardContent,
|
|
@@ -64224,6 +65181,7 @@ export {
|
|
|
64224
65181
|
Progress,
|
|
64225
65182
|
RadioGroup$1 as RadioGroup,
|
|
64226
65183
|
RadioGroupItem,
|
|
65184
|
+
RequireAuth,
|
|
64227
65185
|
ResizableHandle,
|
|
64228
65186
|
ResizablePanel,
|
|
64229
65187
|
ResizablePanelGroup,
|
|
@@ -64249,6 +65207,10 @@ export {
|
|
|
64249
65207
|
SheetHeader,
|
|
64250
65208
|
SheetTitle,
|
|
64251
65209
|
SheetTrigger,
|
|
65210
|
+
ShowWhenAuthenticated,
|
|
65211
|
+
ShowWhenError,
|
|
65212
|
+
ShowWhenLoading,
|
|
65213
|
+
ShowWhenUnauthenticated,
|
|
64252
65214
|
Sidebar,
|
|
64253
65215
|
SidebarContent,
|
|
64254
65216
|
SidebarFooter,
|
|
@@ -64302,27 +65264,63 @@ export {
|
|
|
64302
65264
|
TooltipTrigger,
|
|
64303
65265
|
badgeVariants,
|
|
64304
65266
|
buttonVariants,
|
|
65267
|
+
checkPermissions,
|
|
65268
|
+
checkRoles,
|
|
64305
65269
|
cn$1 as cn,
|
|
64306
65270
|
commonForms,
|
|
64307
65271
|
commonValidations,
|
|
64308
65272
|
conditions,
|
|
65273
|
+
createApolloAuthLink,
|
|
65274
|
+
createAuthAdapter,
|
|
65275
|
+
createAuthFetch,
|
|
65276
|
+
createAxiosAuthInterceptor,
|
|
65277
|
+
createBrowserStorage,
|
|
65278
|
+
createCookieStorage,
|
|
64309
65279
|
createDependency,
|
|
64310
65280
|
createField,
|
|
65281
|
+
createGraphQLAuthAdapter,
|
|
65282
|
+
createMemoryStorage,
|
|
65283
|
+
createRESTAuthAdapter,
|
|
64311
65284
|
createSection,
|
|
65285
|
+
createStorage,
|
|
65286
|
+
createTokenManager,
|
|
64312
65287
|
dotAccessor,
|
|
65288
|
+
evaluatePermissionRule,
|
|
65289
|
+
expandPermissions,
|
|
65290
|
+
expandRoles,
|
|
64313
65291
|
navigationMenuTriggerStyle,
|
|
64314
65292
|
toast,
|
|
64315
65293
|
toggleVariants,
|
|
64316
65294
|
transformers,
|
|
64317
65295
|
useAdminSidebarMenu,
|
|
64318
65296
|
useAdminSidebarMenuRegistration,
|
|
65297
|
+
useAuth,
|
|
65298
|
+
useAuthContext,
|
|
65299
|
+
useAuthError,
|
|
65300
|
+
useAuthPermissions,
|
|
65301
|
+
useAuthRoles,
|
|
65302
|
+
useAuthSession,
|
|
65303
|
+
useAuthStatus,
|
|
65304
|
+
useAuthToken,
|
|
65305
|
+
useAuthUser,
|
|
65306
|
+
useCan,
|
|
64319
65307
|
useDialog,
|
|
64320
65308
|
useDialogController,
|
|
64321
65309
|
useFormBuilder,
|
|
64322
65310
|
useFormField,
|
|
65311
|
+
useIsAuthenticated,
|
|
64323
65312
|
useIsMobile,
|
|
65313
|
+
useIsTokenExpired,
|
|
65314
|
+
useLogin,
|
|
65315
|
+
useLogout,
|
|
65316
|
+
usePermission,
|
|
65317
|
+
useRefresh,
|
|
65318
|
+
useRole,
|
|
65319
|
+
useSetSession,
|
|
64324
65320
|
useSidebar,
|
|
64325
65321
|
useStackDialog,
|
|
64326
65322
|
useTheme,
|
|
64327
|
-
|
|
65323
|
+
useTimeUntilExpiry,
|
|
65324
|
+
validators,
|
|
65325
|
+
withPermission
|
|
64328
65326
|
};
|