Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Feat: Org scoped JWT's CLI support

Daniel Hougaard22b2fb4c988a
diff --git a/frontend/src/views/Login/Login.tsx b/frontend/src/views/Login/Login.tsx
index 31695869f3..307ef2e713 100644
--- a/frontend/src/views/Login/Login.tsx
+++ b/frontend/src/views/Login/Login.tsx
@@ -1,9 +1,7 @@
import { useEffect, useState } from "react";
import { useRouter } from "next/router";
-import axios from "axios";
-import { fetchUserDetails } from "@app/hooks/api/users/queries";
-import { getAuthToken, isLoggedIn } from "@app/reactQuery";
+import { isLoggedIn } from "@app/reactQuery";
import { InitialStep, LDAPStep, MFAStep, SAMLSSOStep } from "./components";
import { navigateUserToSelectOrg } from "./Login.utils";
@@ -18,33 +16,23 @@ export const Login = () => {
useEffect(() => {
// TODO(akhilmhdh): workspace will be controlled by a workspace context
- const redirectToDashboard = async () => {
+ const handleRedirects = async () => {
// TODO(daniel): Move this to select-organization page.
try {
- // user details
- const userDetails = await fetchUserDetails();
- // send details back to client
-
- if (queryParams && queryParams.get("callback_port")) {
- const callbackPort = queryParams.get("callback_port");
-
- // send post request to cli with details
- const cliUrl = `http://127.0.0.1:${callbackPort}/`;
- const instance = axios.create();
- await instance.post(cliUrl, {
- email: userDetails.email,
- privateKey: localStorage.getItem("PRIVATE_KEY"),
- JTWToken: getAuthToken()
- });
+ const callbackPort = queryParams?.get("callback_port");
+ // case: a callback port is set, meaning it's a cli login request: redirect to select org with callback port
+ if (callbackPort) {
+ navigateUserToSelectOrg(router, callbackPort);
+ } else {
+ // case: no callback port, meaning it's a regular login request: redirect to select org
+ navigateUserToSelectOrg(router);
}
-
- navigateUserToSelectOrg(router);
} catch (error) {
console.log("Error - Not logged in yet");
}
};
if (isLoggedIn()) {
- redirectToDashboard();
+ handleRedirects();
}
}, []);
diff --git a/frontend/src/views/Login/Login.utils.tsx b/frontend/src/views/Login/Login.utils.tsx
index 4615d8f270..b6e3c1a105 100644
--- a/frontend/src/views/Login/Login.utils.tsx
+++ b/frontend/src/views/Login/Login.utils.tsx
@@ -27,7 +27,14 @@ export const navigateUserToOrg = async (router: NextRouter, organizationId?: str
}
};
-export const navigateUserToSelectOrg = (router: NextRouter) => {
+export const navigateUserToSelectOrg = (router: NextRouter, cliCallbackPort?: string) => {
queryClient.invalidateQueries(userKeys.getUser);
- router.push("/login/select-organization", undefined, { shallow: true });
+
+ let redirectTo = "/login/select-organization";
+
+ if (cliCallbackPort) {
+ redirectTo += `?callback_port=${cliCallbackPort}`;
+ }
+
+ router.push(redirectTo, undefined, { shallow: true });
};