@crossmint/client-sdk-react-ui 1.3.24 → 1.4.0
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.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -2
- package/dist/index.d.ts +20 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/components/auth/AuthModal.tsx +13 -9
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useCrossmint.test.tsx +43 -7
- package/src/hooks/useCrossmint.tsx +12 -1
- package/src/hooks/useRefreshToken.test.ts +142 -0
- package/src/hooks/useRefreshToken.ts +62 -0
- package/src/index.ts +0 -1
- package/src/providers/CrossmintAuthProvider.test.tsx +102 -12
- package/src/providers/CrossmintAuthProvider.tsx +31 -26
- package/src/utils/authCookies.test.ts +41 -0
- package/src/utils/authCookies.ts +16 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, test } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { waitForSettledState } from "../testUtils";
|
|
4
|
+
import { deleteCookie, getCookie, setCookie } from "./authCookies";
|
|
5
|
+
|
|
6
|
+
describe("authCookies", () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
// Clear all cookies before each test
|
|
9
|
+
document.cookie.split(";").forEach((cookie) => {
|
|
10
|
+
document.cookie = cookie
|
|
11
|
+
.replace(/^ +/, "")
|
|
12
|
+
.replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";path=/");
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test("should return undefined for non-existent cookie", () => {
|
|
17
|
+
expect(getCookie("non-existent")).toBeUndefined();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("should return the correct value for an existing cookie", async () => {
|
|
21
|
+
document.cookie = "test-cookie=test-value";
|
|
22
|
+
await waitForSettledState(() => {
|
|
23
|
+
expect(getCookie("test-cookie")).toBe("test-value");
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("should set a cookie without expiration", async () => {
|
|
28
|
+
setCookie("test-cookie", "test-value");
|
|
29
|
+
await waitForSettledState(() => {
|
|
30
|
+
expect(document.cookie).toContain("test-cookie=test-value");
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("should delete an existing cookie", async () => {
|
|
35
|
+
document.cookie = "test-cookie=test-value";
|
|
36
|
+
deleteCookie("test-cookie");
|
|
37
|
+
await waitForSettledState(() => {
|
|
38
|
+
expect(document.cookie).not.toContain("test-cookie");
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const SESSION_PREFIX = "crossmint-session";
|
|
2
|
+
export const REFRESH_TOKEN_PREFIX = "crossmint-refresh-token";
|
|
3
|
+
|
|
4
|
+
export function getCookie(name: string): string | undefined {
|
|
5
|
+
const crossmintRefreshToken = document.cookie.split("; ").find((row) => row.startsWith(name));
|
|
6
|
+
return crossmintRefreshToken ? crossmintRefreshToken.split("=")[1] : undefined;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function setCookie(name: string, value: string, expiresAt?: string) {
|
|
10
|
+
const expiresInUtc = expiresAt ? new Date(expiresAt).toUTCString() : "";
|
|
11
|
+
document.cookie = `${name}=${value}; ${expiresAt ? `expires=${expiresInUtc};` : ""} path=/; SameSite=Lax;`;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function deleteCookie(name: string) {
|
|
15
|
+
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
|
|
16
|
+
}
|