update to engin

This commit is contained in:
Mann Patel
2025-03-30 00:20:42 -06:00
parent 2e77ef49f4
commit 71a90265d9
3 changed files with 77 additions and 42 deletions

View File

@@ -14,6 +14,7 @@ import Favorites from "./pages/Favorites";
import ProductDetail from "./pages/ProductDetail";
import ItemForm from "./pages/MyListings";
import SearchPage from "./pages/SearchPage"; // Make sure to import the SearchPage
import axios from "axios";
function App() {
// Authentication state - initialize from localStorage if available
@@ -31,6 +32,8 @@ function App() {
const [error, setError] = useState("");
const [isLoading, setIsLoading] = useState(false);
const [userId, setUserId] = useState(null);
// New verification states
const [verificationStep, setVerificationStep] = useState("initial"); // 'initial', 'code-sent', 'verifying'
const [tempUserData, setTempUserData] = useState(null);
@@ -190,6 +193,9 @@ function App() {
sessionStorage.setItem("isAuthenticated", "true");
sessionStorage.setItem("user", JSON.stringify(newUser));
// After successful signup, send session data to server
sendSessionDataToServer(); // Call it after signup
// Reset verification steps
setVerificationStep("initial");
setTempUserData(null);
@@ -293,6 +299,9 @@ function App() {
sessionStorage.setItem("isAuthenticated", "true");
sessionStorage.setItem("user", JSON.stringify(userObj));
// After successful signup, send session data to server
sendSessionDataToServer(); // Call it after signup
sessionStorage.getItem("user");
console.log("Login successful for:", userData.email);
@@ -357,6 +366,48 @@ function App() {
setError("");
};
const sendSessionDataToServer = async () => {
try {
// Retrieve data from sessionStorage
const user = JSON.parse(sessionStorage.getItem("user"));
const isAuthenticated =
sessionStorage.getItem("isAuthenticated") === "true";
if (!user || !isAuthenticated) {
console.log("User is not authenticated");
return;
}
// Prepare the data to send
const requestData = {
userId: user.ID, // or user.ID depending on your user structure
email: user.email,
isAuthenticated,
};
console.log("Sending user data to the server:", requestData);
// Send data to Python server (replace with your actual server URL)
const response = await fetch("http://localhost:5000/api/user/session", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(requestData),
});
// Check the response
if (response.ok) {
const result = await response.json();
console.log("Server response:", result);
} else {
console.error("Failed to send session data to the server");
}
} catch (error) {
console.error("Error sending session data:", error);
}
};
// Login component
const LoginComponent = () => (
<div className="flex h-screen bg-white">