From d62c44b87f5cbae5f60b7720e2dc4867cd400b3b Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Fri, 22 May 2026 20:54:28 +0530 Subject: [PATCH] fix: improve env setup and prevent undefined auth API URL - Add frontend and backend .env.example files - Document required environment variables - Add fallback for VITE_BACKEND_URL in auth pages - Prevent malformed undefined/api/auth/... requests --- .env.example | 6 ++++++ backend/.env.example | 8 ++++++++ src/pages/Login/Login.tsx | 2 +- src/pages/Signup/Signup.tsx | 2 +- 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 .env.example create mode 100644 backend/.env.example diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..9d9a01a6 --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +# Backend API URL +# Local development +VITE_BACKEND_URL=http://localhost:5000 + +# Production example +# VITE_BACKEND_URL=https://your-backend-url.onrender.com diff --git a/backend/.env.example b/backend/.env.example new file mode 100644 index 00000000..e4dd8209 --- /dev/null +++ b/backend/.env.example @@ -0,0 +1,8 @@ +# MongoDB connection string +MONGO_URI=mongodb://localhost:27017/github_tracker + +# Session secret - use a strong random string +SESSION_SECRET=your_session_secret_here + +# Server port +PORT=5000 diff --git a/src/pages/Login/Login.tsx b/src/pages/Login/Login.tsx index 92b7073e..71502503 100644 --- a/src/pages/Login/Login.tsx +++ b/src/pages/Login/Login.tsx @@ -4,7 +4,7 @@ import { useNavigate, Link } from "react-router-dom"; import { ThemeContext } from "../../context/ThemeContext"; import type { ThemeContextType } from "../../context/ThemeContext"; -const backendUrl = import.meta.env.VITE_BACKEND_URL; +const backendUrl = import.meta.env.VITE_BACKEND_URL || ''; interface LoginFormData { email: string; diff --git a/src/pages/Signup/Signup.tsx b/src/pages/Signup/Signup.tsx index 2ac51dcc..398c09f6 100644 --- a/src/pages/Signup/Signup.tsx +++ b/src/pages/Signup/Signup.tsx @@ -6,7 +6,7 @@ import { User, Mail, Lock, Eye, EyeOff } from "lucide-react"; import { ThemeContext } from "../../context/ThemeContext"; import type { ThemeContextType } from "../../context/ThemeContext"; -const backendUrl = import.meta.env.VITE_BACKEND_URL; +const backendUrl = import.meta.env.VITE_BACKEND_URL || ''; interface SignUpFormData { username: string;