Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ const logger = require('./logger');
const app = express();

// CORS configuration
const allowedOrigins = (process.env.FRONTEND_URL || 'http://localhost:5173')
.split(',')
.map((origin) => origin.trim())
.filter(Boolean);

app.use(cors({
origin: allowedOrigins,
credentials: true,
const allowedOrigins = ['http://localhost:5173', 'https://github-spy.etlify.app'];
app.use(cors({
origin: function (origin, callback) {
Expand Down
8 changes: 6 additions & 2 deletions src/pages/Login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ const Login: React.FC = () => {
setIsLoading(true);

try {
const response = await axios.post(`${backendUrl}/api/auth/login`, formData);
const response = await axios.post(
`${backendUrl}/api/auth/login`,
formData,
{ withCredentials: true }
);
setMessage(response.data.message);

if (response.data.message === 'Login successful') {
navigate("/");
navigate("/home");
}
} catch (error: unknown) {
if (axios.isAxiosError(error)) {
Expand Down
33 changes: 33 additions & 0 deletions src/pages/Signup/Signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,39 @@ const SignUp: React.FC = () => {
}
setIsLoading(true);
try {
const response = await axios.post(
`${backendUrl}/api/auth/signup`,
formData,
{ withCredentials: true }
);
setMessage(response.data.message); // Show success message from backend

// Navigate to login page after successful signup
if (response.data.message === 'User created successfully') {
navigate("/login");}


// // Simulate API call (replace with your actual backend integration)
// try {
// // Mock successful signup
// setMessage("Account created successfully! Redirecting to login...");

// // In your actual implementation, integrate with your backend here:
// // const response = await fetch(`${backendUrl}/api/auth/signup`, {
// // method: 'POST',
// // headers: { 'Content-Type': 'application/json' },
// // body: JSON.stringify(formData)
// // });

// setTimeout(() => {
// // Navigate to login page in your actual implementation
// console.log("Redirecting to login page...");
// }, 2000);

Comment thread
coderabbitai[bot] marked this conversation as resolved.
} catch (error) {
setMessage("Something went wrong. Please try again.");
Comment thread
coderabbitai[bot] marked this conversation as resolved.
const response = await axios.post(`${backendUrl}/api/auth/signup`, formData);
setMessage(response.data.message);
const response = await axios.post(`${backendUrl}/api/auth/signup`,
formData // Include cookies for session
);
Expand Down