-
Login
- Endpoint:
POST /api/v1/user/login
- Frontend Usage:
- File:
frontend/src/pages/Login.jsx
- Function:
handleSubmit
- Sends user name and email to the backend to initiate login and receive an OTP.
- File:
- Endpoint:
-
Verify OTP
- Endpoint:
POST /api/v1/user/verify-otp
- Frontend Usage:
- File:
frontend/src/pages/Otp.jsx
- Function:
handleSubmit
- Verifies the OTP entered by the user and generates a JWT token.
- File:
- Endpoint:
-
Resend OTP
- Endpoint:
POST /api/v1/user/resend-otp
- Frontend Usage:
- File:
frontend/src/pages/Otp.jsx
- Function:
handleResend
- Resends the OTP to the user's email.
- File:
- Endpoint:
-
Google Login
- Endpoint:
POST /api/v1/user/google-login
- Frontend Usage:
- File:
frontend/src/pages/Login.jsx
- Function:
handleCredentialResponse
- Logs in the user using Google OAuth.
- File:
- Endpoint:
-
Register Admin
- Endpoint:
POST /api/v1/admin/register
- Frontend Usage: Not implemented in the frontend.
- Registers a new admin (requires admin authentication).
- Endpoint:
-
Admin Login
- Endpoint:
POST /api/v1/admin/login
- Frontend Usage: Not implemented in the frontend.
- Logs in an admin and generates a token.
- Endpoint:
-
Admin Logout
- Endpoint:
POST /api/v1/admin/logout
- Frontend Usage: Not implemented in the frontend.
- Logs out an admin and invalidates the session.
- Endpoint:
-
Book a Bike
- Endpoint:
POST /api/v1/user/book
- Frontend Usage: Not implemented in the frontend.
- Creates a booking for a bike.
- Endpoint:
-
Get Cart
- Endpoint:
GET /api/v1/user/cart/:userId
- Frontend Usage: Not implemented in the frontend.
- Retrieves the cart details for a user.
- Endpoint:
-
Delete Cart
- Endpoint:
DELETE /api/v1/user/cart/:userId
- Frontend Usage: Not implemented in the frontend.
- Deletes the cart for a user.
- Endpoint:
-
Add Accessories to Cart
- Endpoint:
POST /api/v1/user/cart/:userId/accessories
- Frontend Usage: Not implemented in the frontend.
- Adds accessories to the user's cart.
- Endpoint:
-
Get Bikes
- Endpoint:
GET /api/v1/data/bikes
- Frontend Usage:
- File:
frontend/src/pages/Home.jsx
- Function:
useEffect
(fetches bike data on page load). - Retrieves the list of bikes.
- File:
- Endpoint:
-
Get Accessories
- Endpoint:
GET /api/v1/data/accessories
- Frontend Usage:
- File:
frontend/src/pages/Home.jsx
- Function:
useEffect
(fetches accessories data on page load). - Retrieves the list of accessories.
- File:
- Endpoint:
-
Get Reviews
- Endpoint:
GET /api/v1/data/reviews
- Frontend Usage: Not implemented in the frontend.
- Retrieves all reviews.
- Endpoint:
-
Install Axios: Ensure
axios
is installed in the frontend project.npm install axios
-
Fetch Data Example: Use the following code snippet to fetch bike data from the API.
import axios from "axios"; const fetchData = async () => { try { const response = await axios.get("http://localhost:5000/api/v1/data/bikes"); console.log(response.data); } catch (error) { console.error("Error fetching data:", error); } }; fetchData();
-
Fetch Protected Data Example: Use the following code snippet to fetch protected cart data from the API.
const token = localStorage.getItem("token"); const config = { headers: { Authorization: `Bearer ${token}` }, }; const fetchProtectedData = async () => { try { const response = await axios.get("http://localhost:5000/api/v1/user/cart/123", config); console.log(response.data); } catch (error) { console.error("Error fetching protected data:", error); } }; fetchProtectedData();