|
1 | | -import { RequestService, StorageService } from "@formsflow/service"; |
| 1 | +import { RequestService,StorageService } from "@formsflow/service"; |
2 | 2 | import API from "../../endpoints/index"; |
3 | 3 | import { WEB_BASE_CUSTOM_URL } from "../../constants/constants"; |
4 | 4 |
|
| 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 | + |
5 | 35 | /** |
6 | 36 | * Trigger a reset password email/link for the current user. |
7 | 37 | */ |
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 | | -}; |
25 | 38 |
|
26 | 39 | export const requestResetPassword = () => { |
27 | 40 | const token = StorageService.get(StorageService.User.AUTH_TOKEN); |
|
0 commit comments