Skip to content

Commit 7ef7d82

Browse files
committed
fix : Resolve merge conflicts between upstream and origin
2 parents f2c1b27 + 75054ef commit 7ef7d82

19 files changed

Lines changed: 232 additions & 354 deletions

File tree

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VITE_BACKEND_URL=http://localhost:5000

backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"dependencies": {
1414
"bcryptjs": "^2.4.3",
1515
"body-parser": "^1.20.3",
16+
"cors": "^2.8.5",
1617
"dotenv": "^16.4.5",
1718
"express": "^4.21.1",
1819
"express-session": "^1.18.1",

backend/server.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@ const session = require('express-session');
44
const passport = require('passport');
55
const bodyParser = require('body-parser');
66
require('dotenv').config();
7+
const cors = require('cors');
78

89
// Passport configuration
910
require('./config/passportConfig');
1011

1112
const app = express();
1213

14+
// CORS configuration
15+
app.use(cors('*'));
16+
1317
// Middleware
1418
app.use(bodyParser.json());
15-
1619
app.use(session({
1720
secret: process.env.SESSION_SECRET,
1821
resave: false,
1922
saveUninitialized: false,
2023
}));
21-
2224
app.use(passport.initialize());
2325
app.use(passport.session());
2426

@@ -29,7 +31,6 @@ app.use('/api/auth', authRoutes);
2931
// Connect to MongoDB
3032
mongoose.connect(process.env.MONGO_URI, {}).then(() => {
3133
console.log('Connected to MongoDB');
32-
3334
app.listen(process.env.PORT, () => {
3435
console.log(`Server running on port ${process.env.PORT}`);
3536
});

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
5-
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
5+
<link rel="icon" type="image/svg+xml" href="/crl-icon.png" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>Vite + React + TS</title>
7+
<title>Github Tracker</title>
88
</head>
99
<body>
1010
<div id="root"></div>

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,18 @@
1414
"@emotion/styled": "^11.11.0",
1515
"@mui/icons-material": "^5.15.6",
1616
"@mui/material": "^5.15.6",
17-
"@reduxjs/toolkit": "^2.5.0",
1817
"@vitejs/plugin-react": "^4.3.3",
1918
"axios": "^1.7.7",
2019
"octokit": "^4.0.2",
2120
"react": "^18.3.1",
2221
"react-dom": "^18.3.1",
2322
"react-hot-toast": "^2.4.1",
2423
"react-icons": "^5.3.0",
25-
"react-redux": "^9.2.0",
2624
"react-router-dom": "^6.28.0"
2725
},
2826
"devDependencies": {
2927
"@eslint/js": "^9.13.0",
28+
"@types/node": "^22.10.1",
3029
"@types/react": "^18.3.12",
3130
"@types/react-dom": "^18.3.1",
3231
"@types/react-redux": "^7.1.34",

public/crl-icon.png

37.4 KB
Loading

src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function App() {
1616
<Navbar />
1717

1818
{/* Main content */}
19-
<main className="flex-grow bg-gray-100 flex justify-center items-center">
19+
<main className="flex-grow bg-gray-50 flex justify-center items-center p-2">
2020
<Router/>
2121
</main>
2222

@@ -32,7 +32,7 @@ function App() {
3232
toastOptions={{
3333
className: 'bg-white',
3434
duration: 5000,
35-
removeDelay: 1000,
35+
//removeDelay: 1000,
3636

3737
success: {
3838
duration: 3000,

src/Routes/Login/Login.tsx

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import React, { useState, ChangeEvent, FormEvent } from "react";
2+
import axios from "axios";
3+
import { useNavigate, Link } from "react-router-dom"; // Import the hook for navigation
4+
import GithubIcon from "@mui/icons-material/GitHub";
5+
6+
const backendUrl = import.meta.env.VITE_BACKEND_URL;
7+
interface LoginFormData {
8+
email: string;
9+
password: string;
10+
}
11+
12+
const Login: React.FC = () => {
13+
const [formData, setFormData] = useState<LoginFormData>({ email: "", password: "" });
14+
const [message, setMessage] = useState<string>("");
15+
16+
const navigate = useNavigate(); // Initialize the navigate hook
17+
18+
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
19+
const { name, value } = e.target;
20+
setFormData({ ...formData, [name]: value });
21+
};
22+
23+
const handleSubmit = async (e: FormEvent) => {
24+
e.preventDefault();
25+
try {
26+
const response = await axios.post(`${backendUrl}/api/auth/login`,
27+
formData,
28+
29+
);
30+
setMessage(response.data.message); // Show success message from backend
31+
32+
// Navigate to /home if login is successful
33+
if (response.data.message === 'Login successful') {
34+
navigate("/home");
35+
}
36+
} catch (error: any) {
37+
setMessage(error.response?.data?.message || "Something went wrong");
38+
}
39+
};
40+
41+
const handleGithubLogin = async () => {
42+
window.location.href = `${import.meta.env.VITE_API_URL}/auth/github`;
43+
};
44+
45+
return (
46+
<div className="w-[400px] max-w-screen-xl mx-auto bg-white p-8 rounded-lg shadow-md">
47+
<h2 className="text-2xl font-semibold text-center mb-6">Login</h2>
48+
<form onSubmit={handleSubmit} className="space-y-4">
49+
<div>
50+
<input
51+
type="email"
52+
name="email"
53+
placeholder="Email"
54+
value={formData.email}
55+
onChange={handleChange}
56+
required
57+
className="w-full p-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
58+
/>
59+
</div>
60+
<div>
61+
<input
62+
type="password"
63+
name="password"
64+
placeholder="Password"
65+
value={formData.password}
66+
onChange={handleChange}
67+
required
68+
className="w-full p-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
69+
/>
70+
</div>
71+
<button
72+
type="submit"
73+
className="w-full bg-blue-500 text-white py-3 rounded-md hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500"
74+
>
75+
Login
76+
</button>
77+
</form>
78+
<button
79+
onClick={handleGithubLogin}
80+
className="w-full flex items-center justify-center bg-gray-800 text-white py-3 rounded-md hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-gray-500 my-4"
81+
>
82+
<GithubIcon className="mr-4"/>Login with GitHub
83+
</button>
84+
<div className="text-center">
85+
<p className="text-sm text-gray-600">
86+
Don't have an account?{" "}
87+
<Link to="/signup" className="text-blue-500 hover:text-blue-600">
88+
Sign up
89+
</Link>
90+
</p>
91+
</div>
92+
{message && <p className="text-center text-red-500 mt-4">{message}</p>}
93+
</div>
94+
);
95+
};
96+
97+
export default Login;
98+

src/Routes/Router.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@ import Home from "../pages/Home/Home"; // Import the Home component
44
import About from "../pages/About/About"; // Import the About component
55
import Contact from "../pages/Contact/Contact"; // Import the Contact component
66
import Contributors from "../pages/Contributors/Contributors";
7-
import Login from "../pages/Auth/Login";
8-
import Signup from "../pages/Auth/Signup";
7+
import Signup from "./Signup/Signup.tsx";
8+
import Login from "./Login/Login.tsx";
9+
910

1011
const Router = () => {
1112
return (
1213
<Routes>
1314
{/* Redirect from root (/) to the home page */}
15+
<Route path="/signup" element={<Signup />} />
16+
<Route path="/login" element={<Login />} />
1417
<Route path="/" element={<Navigate to="/home" replace />} />
1518
<Route path="/about" element={<About />} />
1619
<Route path="/contact" element={<Contact />} />
1720
<Route path="/home" element={<Home />} />
1821
<Route path="/contributors" element={<Contributors />} />
19-
<Route path="/login" element={<Login />} />
20-
<Route path="/signup" element={<Signup />} />
2122
</Routes>
2223
);
2324
};

src/Routes/Signup/Signup.tsx

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import React, { useState, ChangeEvent, FormEvent } from "react";
2+
import axios from "axios";
3+
import { useNavigate, Link } from "react-router-dom";
4+
5+
const backendUrl = import.meta.env.VITE_BACKEND_URL;
6+
interface SignUpFormData {
7+
username: string;
8+
email: string;
9+
password: string;
10+
}
11+
12+
const SignUp: React.FC = () => {
13+
const [formData, setFormData] = useState<SignUpFormData>({ username: "", email: "", password: "" });
14+
const [message, setMessage] = useState<string>("");
15+
16+
const navigate = useNavigate();
17+
18+
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
19+
const { name, value } = e.target;
20+
setFormData({ ...formData, [name]: value });
21+
};
22+
23+
const handleSubmit = async (e: FormEvent) => {
24+
e.preventDefault();
25+
try {
26+
const response = await axios.post(
27+
`${backendUrl}/api/auth/signup`,
28+
formData // Include cookies for session
29+
);
30+
setMessage(response.data.message); // Show success message from backend
31+
32+
// Navigate to login page after successful signup
33+
if (response.data.message === 'User created successfully') {
34+
navigate("/login");
35+
}
36+
} catch (error: any) {
37+
setMessage(error.response?.data?.message || "Something went wrong");
38+
}
39+
};
40+
41+
return (
42+
<div className="w-[400px] mt-12 max-w-md mx-auto bg-white p-8 rounded-lg shadow-md">
43+
<h2 className="text-2xl font-semibold text-center mb-6">Sign Up</h2>
44+
<form onSubmit={handleSubmit} className="space-y-4">
45+
<div>
46+
<input
47+
type="text"
48+
name="username"
49+
placeholder="Username"
50+
value={formData.username}
51+
onChange={handleChange}
52+
required
53+
className="w-full p-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
54+
/>
55+
</div>
56+
<div>
57+
<input
58+
type="email"
59+
name="email"
60+
placeholder="Email"
61+
value={formData.email}
62+
onChange={handleChange}
63+
required
64+
className="w-full p-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
65+
/>
66+
</div>
67+
<div>
68+
<input
69+
type="password"
70+
name="password"
71+
placeholder="Password"
72+
value={formData.password}
73+
onChange={handleChange}
74+
required
75+
className="w-full p-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
76+
/>
77+
</div>
78+
<button
79+
type="submit"
80+
className="w-full bg-blue-500 text-white py-3 rounded-md hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500"
81+
>
82+
Sign Up
83+
</button>
84+
</form>
85+
<div className="text-center mt-4">
86+
<p className="text-sm text-gray-600">
87+
Already a member?{" "}
88+
<Link to="/login" className="text-blue-500 hover:text-blue-600">
89+
Login
90+
</Link>
91+
</p>
92+
</div>
93+
{message && <p className="text-center text-red-500 mt-4">{message}</p>}
94+
</div>
95+
);
96+
};
97+
98+
export default SignUp;

0 commit comments

Comments
 (0)