ikoncomponents 1.3.2 → 1.3.4

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.
@@ -4,13 +4,13 @@ const cookiePrefix = "ikoncloud_next_";
4
4
  export async function setCookieSession(sessionName, data, options) {
5
5
  const cookieStore = await cookies();
6
6
  cookieStore.set(cookiePrefix + sessionName, data, {
7
- httpOnly: false,
7
+ httpOnly: true,
8
8
  sameSite: "lax",
9
9
  secure: process.env.NODE_ENV === "production",
10
10
  path: "/",
11
11
  domain: process.env.NEXT_PUBLIC_COOKIE_DOMAIN,
12
12
  expires: options === null || options === void 0 ? void 0 : options.expires,
13
- maxAge: options === null || options === void 0 ? void 0 : options.maxAge
13
+ maxAge: options === null || options === void 0 ? void 0 : options.maxAge,
14
14
  });
15
15
  }
16
16
  export async function getCookieSession(sessionName) {
@@ -1,7 +1,9 @@
1
- export interface AccessTokenOptionsProps {
1
+ interface AccessTokenOptionsProps {
2
2
  isNotLogOutWhenExpire?: boolean;
3
3
  isSetToken?: boolean;
4
4
  }
5
5
  export declare function getValidAccessToken(options?: AccessTokenOptionsProps): Promise<string | null>;
6
6
  export declare function refreshAccessToken(refreshToken: string, isSetToken?: boolean): Promise<string | null>;
7
+ export declare function decodeAccessToken(): Promise<import("jwt-decode").JwtPayload | null>;
7
8
  export declare function logOut(): Promise<void>;
9
+ export {};
@@ -1,82 +1,69 @@
1
1
  "use server";
2
2
  import { redirect } from "next/navigation";
3
3
  import { clearAllCookieSession, getCookieSession, setCookieSession, } from "../session/cookieSession";
4
+ import { jwtDecode } from "jwt-decode";
5
+ // Prevent multiple refresh calls at once
6
+ let refreshPromise = null;
4
7
  export async function getValidAccessToken(options) {
5
8
  const accessToken = await getCookieSession("accessToken");
9
+ console.log("Access Token....:");
6
10
  const refreshToken = await getCookieSession("refreshToken");
7
- if (accessToken) {
11
+ console.log("Refresh Token...");
12
+ console.log("Before Return Access Token:...............................................");
13
+ if (accessToken)
8
14
  return accessToken;
9
- }
15
+ console.log("After Return Access Token:...............................................");
10
16
  if (refreshToken) {
11
- // Refresh token is valid, call the refresh token API
12
- const newAccessToken = await refreshAccessToken(refreshToken, options === null || options === void 0 ? void 0 : options.isSetToken);
13
- if (newAccessToken) {
14
- return newAccessToken; // Return the new access token
17
+ console.log("Refreshing access token using refresh token...", refreshToken);
18
+ if (!refreshPromise) {
19
+ refreshPromise = refreshAccessToken(refreshToken, true);
20
+ refreshPromise.finally(() => (refreshPromise = null));
15
21
  }
22
+ return await refreshPromise;
16
23
  }
17
24
  if (!(options === null || options === void 0 ? void 0 : options.isNotLogOutWhenExpire)) {
18
25
  await logOut();
19
26
  }
20
- // If both tokens are invalid, return null
21
27
  return null;
22
28
  }
23
29
  export async function refreshAccessToken(refreshToken, isSetToken) {
24
30
  try {
25
- // Replace this with your actual API call to refresh the token
26
- const response = await fetch(`${process.env.IKON_API_URL}/platform/auth/refresh-token`, {
31
+ console.log("Refreshing access token...");
32
+ const response = await fetch(`https://ikoncloud-dev.keross.com/ikon-api/platform/auth/refresh-token`, {
27
33
  method: "POST",
28
- headers: {
29
- "Content-Type": "application/json",
30
- },
34
+ credentials: "include",
35
+ headers: { "Content-Type": "application/json" },
31
36
  body: JSON.stringify({ refreshToken }),
32
37
  });
33
- if (response.ok) {
34
- const data = await response.json();
35
- const { accessToken, refreshToken, expiresIn, refreshExpiresIn, } = data;
36
- if (isSetToken) {
37
- try {
38
- await setCookieSession("accessToken", accessToken, {
39
- maxAge: expiresIn,
40
- });
41
- await setCookieSession("refreshToken", refreshToken, {
42
- maxAge: refreshExpiresIn,
43
- });
44
- }
45
- catch (error) {
46
- console.error(error);
47
- }
48
- }
49
- // const headerList = headers();
50
- // const protocol = (await headerList).get("x-forwarded-proto") || "http";
51
- // const hostname = (await headerList).get("host") || "localhost:3000";
52
- // const host = `${protocol}://${hostname}`;
53
- // // Save the new access token and its expiration time
54
- // try {
55
- // const res = await fetch(`${host}/api/auth/set-token`, {
56
- // method: "POST",
57
- // headers: {
58
- // "Content-Type": "application/json",
59
- // },
60
- // body: JSON.stringify(tokenData),
61
- // credentials: "include", // Include credentials to send cookies
62
- // });
63
- // if (res.ok) {
64
- // console.log("Token updated successfully");
65
- // } else {
66
- // console.error("Failed to update token");
67
- // }
68
- // } catch (error) {
69
- // console.error("Error updating token:", error);
70
- // }
71
- return accessToken;
38
+ console.log("Refresh Token API Response:", response.status);
39
+ if (!response.ok)
40
+ return null;
41
+ const { accessToken, refreshToken: newRefreshToken, expiresIn, refreshExpiresIn, } = await response.json();
42
+ // Always set new access token
43
+ await setCookieSession("accessToken", accessToken, {
44
+ maxAge: expiresIn,
45
+ });
46
+ // IMPORTANT: Save the rotated refresh token
47
+ if (newRefreshToken) {
48
+ await setCookieSession("refreshToken", newRefreshToken, {
49
+ maxAge: refreshExpiresIn,
50
+ });
51
+ console.log("Refresh token rotated & updated.");
72
52
  }
53
+ console.log(" Access token refreshed successfully.");
54
+ return accessToken;
73
55
  }
74
56
  catch (error) {
75
57
  console.error("Failed to refresh access token:", error);
58
+ return null;
76
59
  }
77
- return null;
60
+ }
61
+ export async function decodeAccessToken() {
62
+ const accessToken = await getValidAccessToken();
63
+ return accessToken ? jwtDecode(accessToken) : null;
78
64
  }
79
65
  export async function logOut() {
80
66
  await clearAllCookieSession();
67
+ console.log("Logging out...");
81
68
  redirect("/login.html");
82
69
  }
package/package.json CHANGED
@@ -1,103 +1,103 @@
1
- {
2
- "name": "ikoncomponents",
3
- "version": "1.3.2",
4
- "main": "dist/index.js",
5
- "types": "dist/index.d.ts",
6
- "css": "dist/styles.css",
7
- "files": [
8
- "dist"
9
- ],
10
- "scripts": {
11
- "build": "npm run build:js && npm run build:css",
12
- "build:js": "tsc -p tsconfig.json",
13
- "build:css": "postcss src/styles.css -o dist/styles.css --config postcss.config.mjs --minify",
14
- "clean": "rimraf dist",
15
- "prepublishOnly": "npm run build"
16
- },
17
- "dependencies": {
18
- "@radix-ui/react-accordion": "^1.2.12",
19
- "@radix-ui/react-alert-dialog": "^1.1.15",
20
- "@radix-ui/react-aspect-ratio": "^1.1.7",
21
- "@radix-ui/react-avatar": "^1.1.10",
22
- "@radix-ui/react-checkbox": "^1.3.3",
23
- "@radix-ui/react-dialog": "^1.1.15",
24
- "@radix-ui/react-dropdown-menu": "^2.1.16",
25
- "@radix-ui/react-hover-card": "^1.1.15",
26
- "@radix-ui/react-icons": "^1.3.0",
27
- "@radix-ui/react-label": "^2.1.7",
28
- "@radix-ui/react-navigation-menu": "^1.2.14",
29
- "@radix-ui/react-popover": "^1.1.15",
30
- "@radix-ui/react-progress": "^1.1.7",
31
- "@radix-ui/react-radio-group": "^1.3.8",
32
- "@radix-ui/react-scroll-area": "^1.2.10",
33
- "@radix-ui/react-select": "^2.2.6",
34
- "@radix-ui/react-separator": "^1.1.7",
35
- "@radix-ui/react-slider": "^1.3.6",
36
- "@radix-ui/react-slot": "^1.2.3",
37
- "@radix-ui/react-switch": "^1.2.6",
38
- "@radix-ui/react-tabs": "^1.1.13",
39
- "@radix-ui/react-toggle": "^1.1.10",
40
- "@radix-ui/react-toggle-group": "^1.1.11",
41
- "@radix-ui/react-tooltip": "^1.2.8",
42
- "@tanstack/react-table": "^8.21.3",
43
- "axios": "^1.13.1",
44
- "class-variance-authority": "^0.7.1",
45
- "clsx": "^2.1.1",
46
- "cmdk": "^1.1.1",
47
- "countries-list": "^3.1.1",
48
- "country-flag-icons": "^1.5.21",
49
- "crypto-js": "^4.2.0",
50
- "date-fns": "^4.1.0",
51
- "echarts": "^6.0.0",
52
- "eslint": "^9",
53
- "framer-motion": "^12.23.22",
54
- "input-otp": "^1.4.2",
55
- "jwt-decode": "^4.0.0",
56
- "lucide-react": "^0.552.0",
57
- "motion": "^12.23.22",
58
- "next": "16.0.0",
59
- "next-themes": "^0.4.6",
60
- "react": "^18.2.0",
61
- "react-big-calendar": "^1.19.4",
62
- "react-cropper": "^2.3.3",
63
- "react-day-picker": "^9.9.0",
64
- "react-dom": "^18.2.0",
65
- "react-hook-form": "^7.64.0",
66
- "shadcn": "^3.5.0",
67
- "sonner": "^2.0.7",
68
- "tailwind-merge": "^3.3.1",
69
- "tailwindcss-animate": "^1.0.7",
70
- "uuid": "^13.0.0",
71
- "vaul": "^1.1.2",
72
- "zxcvbn": "^4.4.2"
73
- },
74
- "devDependencies": {
75
- "@tailwindcss/postcss": "^4",
76
- "@types/crypto-js": "^4.2.2",
77
- "@types/node": "^20",
78
- "@types/react": "^19",
79
- "@types/react-big-calendar": "^1.16.3",
80
- "@types/react-dom": "^19",
81
- "@types/zxcvbn": "^4.4.5",
82
- "autoprefixer": "^10.4.21",
83
- "eslint": "^9",
84
- "eslint-config-next": "16.0.0",
85
- "next": "^14.0.0",
86
- "postcss": "^8.5.6",
87
- "postcss-cli": "^11.0.1",
88
- "postcss-import": "^16.1.1",
89
- "postcss-preset-env": "^10.4.0",
90
- "rimraf": "^6.0.1",
91
- "tailwindcss": "^4",
92
- "tw-animate-css": "^1.4.0",
93
- "typescript": "^5"
94
- },
95
- "peerDependencies": {
96
- "clsx": "^2.1.1",
97
- "next": "16.0.0",
98
- "next-themes": "^0.4.6",
99
- "react": "^18.2.0",
100
- "react-dom": "^18.2.0",
101
- "tailwind-merge": "^3.3.1"
102
- }
103
- }
1
+ {
2
+ "name": "ikoncomponents",
3
+ "version": "1.3.4",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "css": "dist/styles.css",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "npm run build:js && npm run build:css",
12
+ "build:js": "tsc -p tsconfig.json",
13
+ "build:css": "postcss src/styles.css -o dist/styles.css --config postcss.config.mjs --minify",
14
+ "clean": "rimraf dist",
15
+ "prepublishOnly": "npm run build"
16
+ },
17
+ "dependencies": {
18
+ "@radix-ui/react-accordion": "^1.2.12",
19
+ "@radix-ui/react-alert-dialog": "^1.1.15",
20
+ "@radix-ui/react-aspect-ratio": "^1.1.7",
21
+ "@radix-ui/react-avatar": "^1.1.10",
22
+ "@radix-ui/react-checkbox": "^1.3.3",
23
+ "@radix-ui/react-dialog": "^1.1.15",
24
+ "@radix-ui/react-dropdown-menu": "^2.1.16",
25
+ "@radix-ui/react-hover-card": "^1.1.15",
26
+ "@radix-ui/react-icons": "^1.3.0",
27
+ "@radix-ui/react-label": "^2.1.7",
28
+ "@radix-ui/react-navigation-menu": "^1.2.14",
29
+ "@radix-ui/react-popover": "^1.1.15",
30
+ "@radix-ui/react-progress": "^1.1.7",
31
+ "@radix-ui/react-radio-group": "^1.3.8",
32
+ "@radix-ui/react-scroll-area": "^1.2.10",
33
+ "@radix-ui/react-select": "^2.2.6",
34
+ "@radix-ui/react-separator": "^1.1.7",
35
+ "@radix-ui/react-slider": "^1.3.6",
36
+ "@radix-ui/react-slot": "^1.2.3",
37
+ "@radix-ui/react-switch": "^1.2.6",
38
+ "@radix-ui/react-tabs": "^1.1.13",
39
+ "@radix-ui/react-toggle": "^1.1.10",
40
+ "@radix-ui/react-toggle-group": "^1.1.11",
41
+ "@radix-ui/react-tooltip": "^1.2.8",
42
+ "@tanstack/react-table": "^8.21.3",
43
+ "axios": "^1.13.1",
44
+ "class-variance-authority": "^0.7.1",
45
+ "clsx": "^2.1.1",
46
+ "cmdk": "^1.1.1",
47
+ "countries-list": "^3.1.1",
48
+ "country-flag-icons": "^1.5.21",
49
+ "crypto-js": "^4.2.0",
50
+ "date-fns": "^4.1.0",
51
+ "echarts": "^6.0.0",
52
+ "eslint": "^9",
53
+ "framer-motion": "^12.23.22",
54
+ "input-otp": "^1.4.2",
55
+ "jwt-decode": "^4.0.0",
56
+ "lucide-react": "^0.552.0",
57
+ "motion": "^12.23.22",
58
+ "next": "16.0.0",
59
+ "next-themes": "^0.4.6",
60
+ "react": "^18.2.0",
61
+ "react-big-calendar": "^1.19.4",
62
+ "react-cropper": "^2.3.3",
63
+ "react-day-picker": "^9.9.0",
64
+ "react-dom": "^18.2.0",
65
+ "react-hook-form": "^7.64.0",
66
+ "shadcn": "^3.5.0",
67
+ "sonner": "^2.0.7",
68
+ "tailwind-merge": "^3.3.1",
69
+ "tailwindcss-animate": "^1.0.7",
70
+ "uuid": "^13.0.0",
71
+ "vaul": "^1.1.2",
72
+ "zxcvbn": "^4.4.2"
73
+ },
74
+ "devDependencies": {
75
+ "@tailwindcss/postcss": "^4",
76
+ "@types/crypto-js": "^4.2.2",
77
+ "@types/node": "^20",
78
+ "@types/react": "^19",
79
+ "@types/react-big-calendar": "^1.16.3",
80
+ "@types/react-dom": "^19",
81
+ "@types/zxcvbn": "^4.4.5",
82
+ "autoprefixer": "^10.4.21",
83
+ "eslint": "^9",
84
+ "eslint-config-next": "16.0.0",
85
+ "next": "^14.0.0",
86
+ "postcss": "^8.5.6",
87
+ "postcss-cli": "^11.0.1",
88
+ "postcss-import": "^16.1.1",
89
+ "postcss-preset-env": "^10.4.0",
90
+ "rimraf": "^6.0.1",
91
+ "tailwindcss": "^4",
92
+ "tw-animate-css": "^1.4.0",
93
+ "typescript": "^5"
94
+ },
95
+ "peerDependencies": {
96
+ "clsx": "^2.1.1",
97
+ "next": "16.0.0",
98
+ "next-themes": "^0.4.6",
99
+ "react": "^18.2.0",
100
+ "react-dom": "^18.2.0",
101
+ "tailwind-merge": "^3.3.1"
102
+ }
103
+ }