Skip to content

Implement Backend#1

Open
BlockbusterAndy wants to merge 2 commits intoproduction-V2from
feature/backend-implementation
Open

Implement Backend#1
BlockbusterAndy wants to merge 2 commits intoproduction-V2from
feature/backend-implementation

Conversation

@BlockbusterAndy
Copy link
Owner

Add Routing
Implement Backend
Add necessary Dependencies

- Implemented user registration and login features in UserModel.
- Created Login and Register pages with form validation and error handling.
- Integrated React Router for navigation between login, register, and main pages.
- Updated App component to include routing logic.
- Added axios-based apiService for handling API requests to the backend.
- Enhanced styling with Satoshi font and improved CSS structure.
- Updated package.json and package-lock.json to include necessary dependencies.
@BlockbusterAndy BlockbusterAndy requested a review from Copilot June 23, 2025 15:25
@BlockbusterAndy BlockbusterAndy self-assigned this Jun 23, 2025
@BlockbusterAndy BlockbusterAndy added the enhancement New feature or request label Jun 23, 2025
@netlify
Copy link

netlify bot commented Jun 23, 2025

Deploy Preview for passkeep failed.

Name Link
🔨 Latest commit cd4b3e0
🔍 Latest deploy log https://app.netlify.com/projects/passkeep/deploys/685971e650c62b00089498b5

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR integrates the backend API, adds routing with React Router, and introduces React Query for server state management.

  • Adds apiService for register, login, and logout via Axios
  • Implements Register and Login pages with form validation
  • Wraps the app in BrowserRouter and QueryClientProvider, and defines routes in App.jsx

Reviewed Changes

Copilot reviewed 9 out of 11 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/services/apiService.js New Axios client setup and API methods with error handling
src/pages/Register.jsx Registration form component with validation and navigation
src/pages/Login.jsx Login form component with validation and navigation
src/models/UserModel.jsx User model functions wrapping apiService calls
src/main.jsx Added BrowserRouter and React Query provider
src/index.css Imported global font and updated styling rules
src/App.jsx Defined routes for login, register, and protected content
src/.env.example Example environment variable for API URL
package.json Added axios, react-router-dom, and React Query deps

import Manager from "./components/Manager";
import Footer from "./components/Footer";
import { Routes, Route, Navigate } from "react-router-dom";
import Login from "./pages/login";
Copy link

Copilot AI Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import path for the Login component uses lowercase 'login', but the file is named 'Login.jsx'. This will break in case-sensitive environments; update to './pages/Login'.

Suggested change
import Login from "./pages/login";
import Login from "./pages/Login";

Copilot uses AI. Check for mistakes.
Comment on lines +23 to +25
throw error.response.data.message;
}
throw { status: false, message: "Network error occurred" };
Copy link

Copilot AI Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This throws a string here but throws an object in the network error case, leading to inconsistent error shapes. Consider always throwing a single Error object with a message property.

Suggested change
throw error.response.data.message;
}
throw { status: false, message: "Network error occurred" };
throw new Error(error.response.data.message);
}
throw new Error("Network error occurred");

Copilot uses AI. Check for mistakes.
Comment on lines +14 to +25
const apiService = { //register user
register: async (userData) => {
try {
const response = await apiClient.post('auth/register', userData);
return response.data;
} catch (error) {
console.error('Registration failed:', error);
// Throw server response message instead of axios error
if (error.response && error.response.data) {
throw error.response.data.message;
}
throw { status: false, message: "Network error occurred" };
Copy link

Copilot AI Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Error handling in register, login, and logout is duplicated. Extract a shared helper to parse and rethrow API errors to DRY up this logic.

Suggested change
const apiService = { //register user
register: async (userData) => {
try {
const response = await apiClient.post('auth/register', userData);
return response.data;
} catch (error) {
console.error('Registration failed:', error);
// Throw server response message instead of axios error
if (error.response && error.response.data) {
throw error.response.data.message;
}
throw { status: false, message: "Network error occurred" };
const handleApiError = (error, context) => {
console.error(`${context} failed:`, error);
if (error.response && error.response.data) {
throw error.response.data.message;
}
throw { status: false, message: "Network error occurred" };
};
const apiService = { //register user
register: async (userData) => {
try {
const response = await apiClient.post('auth/register', userData);
return response.data;
} catch (error) {
handleApiError(error, 'Registration');

Copilot uses AI. Check for mistakes.
navigate('/login');
} catch (error) {
console.error('Registration failed:', error);
setErrors({ ...errors, email: error.message });
Copy link

Copilot AI Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The catch block assumes error has a message property, but apiService may throw a raw string. This could set email to undefined—normalize the error into an object before accessing message.

Copilot uses AI. Check for mistakes.
Comment on lines +31 to +32
console.error("Login failed:", error);
setErrors({ ...errors, email: error.message });
Copy link

Copilot AI Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The catch block accesses error.message, but thrown errors may be plain strings, leading to undefined. Normalize or wrap the error so you always have a message property.

Suggested change
console.error("Login failed:", error);
setErrors({ ...errors, email: error.message });
const normalizedError = error instanceof Error ? error : new Error(String(error));
console.error("Login failed:", normalizedError);
setErrors({ ...errors, email: normalizedError.message });

Copilot uses AI. Check for mistakes.
@import "tailwindcss";
@plugin "daisyui";

* {
Copy link

Copilot AI Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The global * selector applies the font to every element, which can be heavy and affect third-party widgets. Consider scoping this to body or a root container.

Suggested change
* {
body {

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants