Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

Session management update (#281)

Athul09c8bd039826
diff --git a/frontend/src/components/set-org/SetOrg.jsx b/frontend/src/components/set-org/SetOrg.jsx
index fb2f396ac..ff5a3a6aa 100644
--- a/frontend/src/components/set-org/SetOrg.jsx
+++ b/frontend/src/components/set-org/SetOrg.jsx
@@ -1,5 +1,4 @@
import Cookies from "js-cookie";
-import { userSession } from "../../helpers/GetUserSession.js";
import { useEffect, useState } from "react";
import { Button, Card } from "antd";
import { useLocation, useNavigate } from "react-router-dom";
@@ -15,6 +14,7 @@ import {
} from "../../assets/index";
import { useExceptionHandler } from "../../hooks/useExceptionHandler";
import { useAlertStore } from "../../store/alert-store";
+import { useUserSession } from "../../hooks/useUserSession.js";
function SetOrg() {
const { state } = useLocation();
@@ -23,7 +23,7 @@ function SetOrg() {
const [loadingOrgId, setLoadingOrgId] = useState(null);
const { setAlertDetails } = useAlertStore();
const handleException = useExceptionHandler();
-
+ const userSession = useUserSession();
useEffect(() => {
const fetchData = async () => {
try {
diff --git a/frontend/src/helpers/GetUserSession.js b/frontend/src/helpers/GetUserSession.js
deleted file mode 100644
index 79b0564ac..000000000
--- a/frontend/src/helpers/GetUserSession.js
+++ /dev/null
@@ -1,19 +0,0 @@
-import axios from "axios";
-import { useExceptionHandler } from "../hooks/useExceptionHandler.jsx";
-import { useAlertStore } from "../store/alert-store";
-const userSession = async () => {
- try {
- const requestOptions = {
- method: "GET",
- url: "/api/v1/session",
- };
- const res = await axios(requestOptions);
- return res.data;
- } catch (error) {
- const handleException = useExceptionHandler();
- const { setAlertDetails } = useAlertStore();
- setAlertDetails(handleException(error, "Error while getting session"));
- }
-};
-
-export { userSession };
diff --git a/frontend/src/hooks/useSessionValid.js b/frontend/src/hooks/useSessionValid.js
index ea922f3d9..3f2026261 100644
--- a/frontend/src/hooks/useSessionValid.js
+++ b/frontend/src/hooks/useSessionValid.js
@@ -2,10 +2,10 @@ import axios from "axios";
import { getSessionData } from "../helpers/GetSessionData";
import Cookies from "js-cookie";
-import { userSession } from "../helpers/GetUserSession.js";
import { useSessionStore } from "../store/session-store";
import { useExceptionHandler } from "../hooks/useExceptionHandler.jsx";
import { useNavigate } from "react-router-dom";
+import { useUserSession } from "./useUserSession.js";
let getTrialDetails;
try {
@@ -18,6 +18,7 @@ function useSessionValid() {
const setSessionDetails = useSessionStore((state) => state.setSessionDetails);
const handleException = useExceptionHandler();
const navigate = useNavigate();
+ const userSession = useUserSession();
return async () => {
try {
const userSessionData = await userSession();
diff --git a/frontend/src/hooks/useUserSession.js b/frontend/src/hooks/useUserSession.js
new file mode 100644
index 000000000..51566f4c7
--- /dev/null
+++ b/frontend/src/hooks/useUserSession.js
@@ -0,0 +1,34 @@
+import axios from "axios";
+import { useNavigate } from "react-router-dom";
+
+import { useExceptionHandler } from "../hooks/useExceptionHandler.jsx";
+import { useAlertStore } from "../store/alert-store";
+const useUserSession = () => {
+ const navigate = useNavigate();
+ const handleException = useExceptionHandler();
+ const { setAlertDetails } = useAlertStore();
+ const fallbackErrorMessage = "Error while getting session";
+
+ return async () => {
+ try {
+ const requestOptions = {
+ method: "GET",
+ url: "/api/v1/session",
+ };
+ const res = await axios(requestOptions);
+ return res.data;
+ } catch (error) {
+ if (error?.response?.statusText === "Unauthorized") {
+ return;
+ }
+
+ if (error?.response?.statusText === "Payment Required") {
+ navigate("/trial-expired");
+ return;
+ }
+
+ setAlertDetails(handleException(error, fallbackErrorMessage));
+ }
+ };
+};
+export { useUserSession };