@djangocfg/api 2.1.27 → 2.1.28
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/auth.cjs +59 -3
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +23 -1
- package/dist/auth.d.ts +23 -1
- package/dist/auth.mjs +59 -3
- package/dist/auth.mjs.map +1 -1
- package/package.json +3 -3
- package/src/auth/hooks/index.ts +2 -1
- package/src/auth/hooks/useBase64.ts +80 -0
- package/src/auth/hooks/useProfileCache.ts +10 -3
package/dist/auth.cjs
CHANGED
|
@@ -38,6 +38,8 @@ __export(auth_exports, {
|
|
|
38
38
|
PatchedUserProfileUpdateRequestSchema: () => PatchedUserProfileUpdateRequestSchema,
|
|
39
39
|
authLogger: () => authLogger,
|
|
40
40
|
clearProfileCache: () => clearProfileCache,
|
|
41
|
+
decodeBase64: () => decodeBase64,
|
|
42
|
+
encodeBase64: () => encodeBase64,
|
|
41
43
|
formatAuthError: () => formatAuthError,
|
|
42
44
|
getCacheMetadata: () => getCacheMetadata,
|
|
43
45
|
getCachedProfile: () => getCachedProfile,
|
|
@@ -50,6 +52,7 @@ __export(auth_exports, {
|
|
|
50
52
|
useAuthGuard: () => useAuthGuard,
|
|
51
53
|
useAuthRedirectManager: () => useAuthRedirectManager,
|
|
52
54
|
useAutoAuth: () => useAutoAuth,
|
|
55
|
+
useBase64: () => useBase64,
|
|
53
56
|
useGithubAuth: () => useGithubAuth,
|
|
54
57
|
useLocalStorage: () => useLocalStorage2,
|
|
55
58
|
useSessionStorage: () => useSessionStorage,
|
|
@@ -4530,6 +4533,56 @@ var logger = (0, import_consola30.createConsola)({
|
|
|
4530
4533
|
}).withTag("api");
|
|
4531
4534
|
var authLogger = logger.withTag("auth");
|
|
4532
4535
|
|
|
4536
|
+
// src/auth/hooks/useBase64.ts
|
|
4537
|
+
var isDev = process.env.NODE_ENV === "development";
|
|
4538
|
+
function encodeBase64(data) {
|
|
4539
|
+
if (isDev) {
|
|
4540
|
+
return data;
|
|
4541
|
+
}
|
|
4542
|
+
try {
|
|
4543
|
+
if (typeof window !== "undefined") {
|
|
4544
|
+
return btoa(encodeURIComponent(data).replace(/%([0-9A-F]{2})/g, (_, p1) => {
|
|
4545
|
+
return String.fromCharCode(parseInt(p1, 16));
|
|
4546
|
+
}));
|
|
4547
|
+
}
|
|
4548
|
+
return Buffer.from(data, "utf-8").toString("base64");
|
|
4549
|
+
} catch (error) {
|
|
4550
|
+
console.error("Base64 encoding error:", error);
|
|
4551
|
+
return data;
|
|
4552
|
+
}
|
|
4553
|
+
}
|
|
4554
|
+
__name(encodeBase64, "encodeBase64");
|
|
4555
|
+
function decodeBase64(encoded) {
|
|
4556
|
+
if (isDev) {
|
|
4557
|
+
return encoded;
|
|
4558
|
+
}
|
|
4559
|
+
try {
|
|
4560
|
+
if (typeof window !== "undefined") {
|
|
4561
|
+
const binary = atob(encoded);
|
|
4562
|
+
const bytes = new Uint8Array(binary.length);
|
|
4563
|
+
for (let i = 0; i < binary.length; i++) {
|
|
4564
|
+
bytes[i] = binary.charCodeAt(i);
|
|
4565
|
+
}
|
|
4566
|
+
return decodeURIComponent(
|
|
4567
|
+
Array.from(bytes).map((byte) => "%" + ("00" + byte.toString(16)).slice(-2)).join("")
|
|
4568
|
+
);
|
|
4569
|
+
}
|
|
4570
|
+
return Buffer.from(encoded, "base64").toString("utf-8");
|
|
4571
|
+
} catch (error) {
|
|
4572
|
+
console.error("Base64 decoding error:", error);
|
|
4573
|
+
return encoded;
|
|
4574
|
+
}
|
|
4575
|
+
}
|
|
4576
|
+
__name(decodeBase64, "decodeBase64");
|
|
4577
|
+
function useBase64() {
|
|
4578
|
+
return {
|
|
4579
|
+
encode: encodeBase64,
|
|
4580
|
+
decode: decodeBase64,
|
|
4581
|
+
isDev
|
|
4582
|
+
};
|
|
4583
|
+
}
|
|
4584
|
+
__name(useBase64, "useBase64");
|
|
4585
|
+
|
|
4533
4586
|
// src/auth/hooks/useProfileCache.ts
|
|
4534
4587
|
var CACHE_KEY = "user_profile_cache";
|
|
4535
4588
|
var CACHE_VERSION = 1;
|
|
@@ -4542,7 +4595,8 @@ function getCachedProfile() {
|
|
|
4542
4595
|
authLogger.debug("No cached profile found");
|
|
4543
4596
|
return null;
|
|
4544
4597
|
}
|
|
4545
|
-
const
|
|
4598
|
+
const decoded = decodeBase64(cached);
|
|
4599
|
+
const cachedData = JSON.parse(decoded);
|
|
4546
4600
|
if (cachedData.version !== CACHE_VERSION) {
|
|
4547
4601
|
authLogger.warn("Cache version mismatch, clearing cache");
|
|
4548
4602
|
clearProfileCache();
|
|
@@ -4573,7 +4627,8 @@ function setCachedProfile(profile, options) {
|
|
|
4573
4627
|
timestamp: Date.now(),
|
|
4574
4628
|
ttl: options?.ttl || DEFAULT_TTL
|
|
4575
4629
|
};
|
|
4576
|
-
|
|
4630
|
+
const encoded = encodeBase64(JSON.stringify(cachedData));
|
|
4631
|
+
localStorage.setItem(CACHE_KEY, encoded);
|
|
4577
4632
|
authLogger.debug("Profile cached, TTL:", cachedData.ttl / 1e3, "seconds");
|
|
4578
4633
|
} catch (error) {
|
|
4579
4634
|
authLogger.error("Error writing cache:", error);
|
|
@@ -4599,7 +4654,8 @@ function getCacheMetadata() {
|
|
|
4599
4654
|
if (typeof window === "undefined") return null;
|
|
4600
4655
|
const cached = localStorage.getItem(CACHE_KEY);
|
|
4601
4656
|
if (!cached) return { exists: false };
|
|
4602
|
-
const
|
|
4657
|
+
const decoded = decodeBase64(cached);
|
|
4658
|
+
const cachedData = JSON.parse(decoded);
|
|
4603
4659
|
const now = Date.now();
|
|
4604
4660
|
const age = now - cachedData.timestamp;
|
|
4605
4661
|
const expiresIn = cachedData.ttl - age;
|