Update environment variables, add fingerprinting, and refactor API endpoints
- Changed server socket and REST API base URLs in .env file. - Added FingerprintJS dependencies to package.json and package-lock.json. - Implemented fingerprint generation in UserAuth component. - Updated API endpoints from v1 to v2 in various service files. - Refactored API calls to include authorization tokens. - Commented out console log statements for cleaner production code.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { useState, FormEvent } from "react";
|
||||
import React, { useState, FormEvent, useEffect } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { LogoIconLarge } from "../components/icons/Logo";
|
||||
import { EyeIcon } from "../components/icons/ExportCommonIcons";
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
} from "../store/builder/store";
|
||||
import { signInApi } from "../services/factoryBuilder/signInSignUp/signInApi";
|
||||
import { signUpApi } from "../services/factoryBuilder/signInSignUp/signUpApi";
|
||||
import FingerprintJS from "@fingerprintjs/fingerprintjs";
|
||||
|
||||
const UserAuth: React.FC = () => {
|
||||
const [email, setEmail] = useState("");
|
||||
@@ -19,33 +20,62 @@ const UserAuth: React.FC = () => {
|
||||
const { userName, setUserName } = useUserName();
|
||||
const { setOrganization } = useOrganization();
|
||||
const { setLoadingProgress } = useLoadingProgress();
|
||||
const [fingerprint, setFingerprint] = useState("");
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
const initializeFingerprint = async () => {
|
||||
const fp = await FingerprintJS.load();
|
||||
const result = await fp.get();
|
||||
setFingerprint(result.visitorId); // Set the fingerprint
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
initializeFingerprint();
|
||||
}, [])
|
||||
|
||||
|
||||
const handleLogin = async (e: FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
|
||||
const organization = email.split("@")[1].split(".")[0];
|
||||
console.log('email, password, organization: ', email, password, organization);
|
||||
|
||||
try {
|
||||
const res = await signInApi(email, password, organization);
|
||||
|
||||
|
||||
if (res.message === "login successfull") {
|
||||
const res = await signInApi(email, password, organization, fingerprint);
|
||||
if (res.message.message === "login successfull") {
|
||||
setError("");
|
||||
setOrganization(organization);
|
||||
setUserName(res.name);
|
||||
console.log(' res.userId: ', res.userId);
|
||||
localStorage.setItem("userId", res.userId);
|
||||
localStorage.setItem("email", res.email);
|
||||
localStorage.setItem("userName", res.name);
|
||||
if (res.isShare) {
|
||||
setUserName(res.message.name);
|
||||
// console.log(' res.userId: ', res.message.userId);
|
||||
localStorage.setItem("userId", res.message.userId);
|
||||
localStorage.setItem("email", res.message.email);
|
||||
localStorage.setItem("userName", res.message.name);
|
||||
localStorage.setItem("token", res.message.token);
|
||||
localStorage.setItem("refreshToken", res.message.refreshToken);
|
||||
|
||||
if (res.message.isShare) {
|
||||
setLoadingProgress(1);
|
||||
// navigate("/Project");
|
||||
navigate("/Dashboard");
|
||||
}
|
||||
} else if (res.message === "User Not Found!!! Kindly signup...") {
|
||||
setError("Account not found");
|
||||
} else if (res.message === "Already LoggedIn on another browser....Please logout!!!") {
|
||||
setError("Already logged in on another browser. Please logout first.");
|
||||
navigate("/");
|
||||
setError("")
|
||||
// setError("");
|
||||
// setOrganization(organization);
|
||||
// setUserName(res.ForceLogoutData.userName);
|
||||
// console.log(' res.userId: ', res.ForceLogoutData.userId);
|
||||
// localStorage.setItem("userId", res.ForceLogoutData.userId);
|
||||
// localStorage.setItem("email", res.ForceLogoutData.Email);
|
||||
// localStorage.setItem("userName", res.ForceLogoutData.userName);
|
||||
// localStorage.setItem("token", res.ForceLogoutData.token);
|
||||
// localStorage.setItem("refreshToken", res.ForceLogoutData.refreshToken);
|
||||
// if (res.ForceLogoutData.isShare) {
|
||||
// setLoadingProgress(1);
|
||||
// navigate("/Dashboard");
|
||||
// }
|
||||
}
|
||||
} catch (error) {
|
||||
echo.error("Login failed");
|
||||
|
||||
Reference in New Issue
Block a user