Refactor code, split routes, change url in backend and update in frontend. Still have bugs, infinite loading after signup?

This commit is contained in:
estherdev03
2025-03-19 02:09:30 -06:00
parent 3ac9ed00a2
commit c75fa01392
14 changed files with 582 additions and 510 deletions

View File

@@ -59,16 +59,19 @@ function App() {
console.log("Sending verification code to:", userData.email);
// Make API call to send verification code
const response = await fetch("http://localhost:3030/send-verification", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email: userData.email,
// Add any other required fields
}),
});
const response = await fetch(
"http://localhost:3030/api/user/send-verification",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email: userData.email,
// Add any other required fields
}),
}
);
if (!response.ok) {
throw new Error("Failed to send verification code");
@@ -105,16 +108,19 @@ function App() {
console.log("Verifying code:", code);
// Make API call to verify code
const response = await fetch("http://localhost:3030/verify-code", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email: tempUserData.email,
code: code,
}),
});
const response = await fetch(
"http://localhost:3030/api/user/verify-code",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email: tempUserData.email,
code: code,
}),
}
);
if (!response.ok) {
throw new Error("Failed to verify code");
@@ -149,13 +155,16 @@ function App() {
console.log(userData);
// Make API call to complete signup
const response = await fetch("http://localhost:3030/complete-signup", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(userData),
});
const response = await fetch(
"http://localhost:3030/api/user/complete-signup",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(userData),
}
);
if (!response.ok) {
throw new Error("Failed to complete signup");
@@ -245,16 +254,19 @@ function App() {
});
// Make API call to localhost:3030/find_user
const response = await fetch("http://localhost:3030/find_user", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email: formValues.email,
password: formValues.password,
}),
});
const response = await fetch(
"http://localhost:3030/api/user/find_user",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email: formValues.email,
password: formValues.password,
}),
}
);
if (!response.ok) {
throw new Error("Network response was not ok");
@@ -497,8 +509,8 @@ function App() {
{isLoading
? "Please wait..."
: isSignUp
? "Create Account"
: "Sign In"}
? "Create Account"
: "Sign In"}
</button>
</div>
</form>

View File

@@ -1,10 +1,10 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.jsx'
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import "./index.css";
import App from "./App.jsx";
createRoot(document.getElementById('root')).render(
createRoot(document.getElementById("root")).render(
<StrictMode>
<App />
</StrictMode>,
)
</StrictMode>
);

View File

@@ -10,7 +10,9 @@ const Home = () => {
useEffect(() => {
const fetchProducts = async () => {
try {
const response = await fetch("http://localhost:3030/get_product");
const response = await fetch(
"http://localhost:3030/api/product/get_product"
);
if (!response.ok) throw new Error("Failed to fetch products");
const data = await response.json();
@@ -27,7 +29,7 @@ const Home = () => {
seller: "Unknown", // Modify if seller info is available
datePosted: "Just now",
isFavorite: false,
})),
}))
);
} else {
throw new Error(data.message || "Error fetching products");
@@ -48,8 +50,8 @@ const Home = () => {
prevListings.map((listing) =>
listing.id === id
? { ...listing, isFavorite: !listing.isFavorite }
: listing,
),
: listing
)
);
};

View File

@@ -33,15 +33,18 @@ const Settings = () => {
}
// Make API call to fetch user data
const response = await fetch("http://localhost:3030/find_user", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email: storedUser.email,
}),
});
const response = await fetch(
"http://localhost:3030/api/user/find_user",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email: storedUser.email,
}),
}
);
const data = await response.json();
console.log(data);
@@ -67,7 +70,7 @@ const Settings = () => {
} catch (error) {
console.error("Error fetching user data:", error);
setError(
error.message || "An error occurred while loading your profile",
error.message || "An error occurred while loading your profile"
);
} finally {
setIsLoading(false);
@@ -153,7 +156,7 @@ const Settings = () => {
const handleDeleteAccount = async () => {
if (
window.confirm(
"Are you sure you want to delete your account? This action cannot be undone.",
"Are you sure you want to delete your account? This action cannot be undone."
)
) {
try {
@@ -166,7 +169,7 @@ const Settings = () => {
}
// Make API call to delete the account
const response = await fetch("http://localhost:3030/delete", {
const response = await fetch("http://localhost:3030/api/user/delete", {
method: "POST",
headers: {
"Content-Type": "application/json",