Skip to content

Commit f9c26d0

Browse files
authored
Merge pull request #1103 from fahad-aot/feature/fwf-5993-integrate-login-detials-api
feature/fwf-5993:Integrated federated login details
2 parents 5c35b9c + 8a5e3a7 commit f9c26d0

File tree

4 files changed

+38
-28
lines changed

4 files changed

+38
-28
lines changed

forms-flow-components/src/components/CustomComponents/FilterableDropdown.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,6 @@ export const FilterableDropdown: React.FC<FilterableDropdownProps> = ({
9797
return options.find((opt) => opt.value === value || opt.value === defaultValue);
9898
}, [options, value, defaultValue]);
9999

100-
// Console options on load
101-
useEffect(() => {
102-
console.log("FilterableDropdown options on load:", options);
103-
}, [options]);
104-
105-
// Console dropdown state
106-
useEffect(() => {
107-
console.log("FilterableDropdown isOpen:", isOpen);
108-
}, [isOpen]);
109100

110101
// Initialize input value with selected option label only when dropdown is closed and user is not typing
111102
useEffect(() => {

forms-flow-nav/src/endpoints/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ const API = {
44
LANG_UPDATE: `${WEB_BASE_URL}/user/locale`,
55
RESET_PASSWORD: (userId) => `${WEB_BASE_URL}/user/${userId}/reset-password`,
66
GET_TENANT_DATA: `${MT_ADMIN_BASE_URL}/${MT_ADMIN_BASE_URL_VERSION}/tenant`,
7-
INTEGRATION_ENABLE_DETAILS: `${WEB_BASE_URL}/integrations/embed/display`
7+
INTEGRATION_ENABLE_DETAILS: `${WEB_BASE_URL}/integrations/embed/display`,
8+
USER_LOGIN_DETAILS: (userId) => `${WEB_BASE_URL}/user/${userId}/login-details`,
89
}
910

1011
export default API;

forms-flow-nav/src/services/user/index.js

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,40 @@
1-
import { RequestService, StorageService } from "@formsflow/service";
1+
import { RequestService,StorageService } from "@formsflow/service";
22
import API from "../../endpoints/index";
33
import { WEB_BASE_CUSTOM_URL } from "../../constants/constants";
44

5+
const extractUserIdFromToken = (token) => {
6+
if (!token) return "";
7+
const raw = String(token).replace(/^Bearer\s+/i, "").trim();
8+
const parts = raw.split(".");
9+
if (parts.length < 2) return "";
10+
try {
11+
const base64Url = parts[1];
12+
const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
13+
const padded = base64.padEnd(base64.length + ((4 - (base64.length % 4)) % 4), "=");
14+
const atobFn = typeof atob === "function" ? atob : (typeof window !== "undefined" ? window.atob : null);
15+
if (!atobFn) return "";
16+
const json = JSON.parse(atobFn(padded));
17+
return json?.sub || "";
18+
} catch (e) {
19+
return "";
20+
}
21+
};
22+
export const fetchUserLoginDetails = () => {
23+
const userId = extractUserIdFromToken(StorageService.get(StorageService.User.AUTH_TOKEN));
24+
if (!userId) return;
25+
const apiUserLoginDetails = API.USER_LOGIN_DETAILS(userId);
26+
RequestService.httpGETRequest(apiUserLoginDetails, null, StorageService.get(StorageService.User.AUTH_TOKEN))
27+
.then((res) => {
28+
localStorage.setItem("USER_LOGIN_DETAILS", JSON.stringify(res.data));
29+
})
30+
.catch((error) => {
31+
console.error(error);
32+
});
33+
};
34+
535
/**
636
* Trigger a reset password email/link for the current user.
737
*/
8-
const extractUserIdFromToken = (token) => {
9-
if (!token) return "";
10-
const raw = String(token).replace(/^Bearer\s+/i, "").trim();
11-
const parts = raw.split(".");
12-
if (parts.length < 2) return "";
13-
try {
14-
const base64Url = parts[1];
15-
const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
16-
const padded = base64.padEnd(base64.length + ((4 - (base64.length % 4)) % 4), "=");
17-
const atobFn = typeof atob === "function" ? atob : (typeof window !== "undefined" ? window.atob : null);
18-
if (!atobFn) return "";
19-
const json = JSON.parse(atobFn(padded));
20-
return json?.sub || "";
21-
} catch (e) {
22-
return "";
23-
}
24-
};
2538

2639
export const requestResetPassword = () => {
2740
const token = StorageService.get(StorageService.User.AUTH_TOKEN);

forms-flow-nav/src/sidenav/Sidebar.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { fetchTenantDetails } from "../services/tenant";
2222
import { setShowApplications } from "../constants/userContants";
2323
import { LANGUAGE } from "../constants/constants";
2424
import { checkIntegrationEnabled } from "../services/integration";
25+
import { fetchUserLoginDetails } from "../services/user";
2526
import MenuComponent from "./MenuComponent";
2627
// import Appname from "./formsflow.svg";
2728
import { ApplicationLogo, LogoutIcon, MenuToggleIcon } from "@formsflow/components";
@@ -244,8 +245,12 @@ const Sidebar = React.memo(({ props, sidenavHeight="100%" }) => {
244245
});
245246
}, []);
246247

248+
// On successful authentication, load federated login details and integration config
247249
useEffect(() => {
248250
if (isAuthenticated) {
251+
// Fetch federated login details (saves into localStorage)]
252+
fetchUserLoginDetails();
253+
249254
checkIntegrationEnabled()
250255
.then((res) => {
251256
setIntegrationEnabled(res.data?.enabled);

0 commit comments

Comments
 (0)