diff --git a/backend/config/db.js b/backend/config/db.js index 5be0171f..6e8351e0 100644 --- a/backend/config/db.js +++ b/backend/config/db.js @@ -1,9 +1,19 @@ import mongoose from "mongoose"; +import { MongoMemoryServer } from "mongodb-memory-server"; // Connect to MongoDB database using try catch block const connectDB = async () => { try { - await mongoose.connect(process.env.MONGO_URI); + let uri = process.env.MONGO_URI; + + // Check if URI is the default template or invalid + if (!uri || uri === "your_mongodb_atlas_connection_string" || (!uri.startsWith("mongodb://") && !uri.startsWith("mongodb+srv://"))) { + console.log("No valid MONGO_URI found in .env. Starting in-memory MongoDB instance for local development..."); + const mongoServer = await MongoMemoryServer.create(); + uri = mongoServer.getUri(); + } + + await mongoose.connect(uri); console.log("Connection to MongoDB successful"); } catch (error) { console.error("Error connecting to MongoDB:", error.message); diff --git a/frontend/src/components/Navbar.jsx b/frontend/src/components/Navbar.jsx index 2a988059..66c81e09 100644 --- a/frontend/src/components/Navbar.jsx +++ b/frontend/src/components/Navbar.jsx @@ -2,7 +2,7 @@ import { useState, useContext, useEffect } from "react"; import { Link, NavLink, useLocation } from "react-router-dom"; // eslint-disable-next-line no-unused-vars import { motion, AnimatePresence } from "framer-motion"; -import { Menu, X, LayoutDashboard, CheckSquare, Calendar, LogOut, LogIn, User, Sun, Moon, TrendingUp } from "lucide-react"; +import { Menu, X, LayoutDashboard, CheckSquare, Calendar, LogOut, LogIn, UserPlus, Sun, Moon, TrendingUp, User } from "lucide-react"; import { AuthContext } from "../context/AuthContext"; import { ThemeContext } from "../context/ThemeContext"; import { clsx } from "clsx"; @@ -13,6 +13,15 @@ function cn(...inputs) { return twMerge(clsx(inputs)); } +// Navigation Links configuration +const navLinks = [ + { name: "Dashboard", path: "/dashboard", icon: LayoutDashboard }, + { name: "Tasks", path: "/tasks", icon: CheckSquare }, + { name: "Routine Builder", path: "/routine-builder", icon: Calendar }, + { name: "Analytics", path: "/analytics", icon: TrendingUp }, + { name: "Profile", path: "/profile", icon: User }, +]; + //logout modal const LogoutModal = ({ isOpen, onConfirm, onCancel }) => ( @@ -72,12 +81,12 @@ const LogoutModal = ({ isOpen, onConfirm, onCancel }) => ( ); const Navbar = () => { - const { user, logout } = useContext(AuthContext); + const { token, logout } = useContext(AuthContext); const { theme, toggleTheme } = useContext(ThemeContext); const [isOpen, setIsOpen] = useState(false); const [scrolled, setScrolled] = useState(false); + const [isLogoutModalOpen, setIsLogoutModalOpen] = useState(false); const location = useLocation(); - const [showLogoutModal, setShowLogoutModal] = useState(false); // Handle scroll effect for premium glassmorphism transition useEffect(() => { @@ -94,38 +103,17 @@ const Navbar = () => { setIsOpen(false); }, [location.pathname]); -const handleLogoutClick = () => { - setShowLogoutModal(true); + const handleLogout = () => { + setIsLogoutModalOpen(true); }; - const handleConfirmLogout = () => { - setShowLogoutModal(false); - setIsOpen(false); + const confirmLogout = () => { logout(); + setIsOpen(false); + setIsLogoutModalOpen(false); }; - const handleCancelLogout = () => { - setShowLogoutModal(false); - }; - - // Navigation Links configuration - const navLinks = [ - { name: "Dashboard", path: "/dashboard", icon: LayoutDashboard }, - { name: "Tasks", path: "/tasks", icon: CheckSquare }, - { name: "Routine Builder", path: "/routine-builder", icon: Calendar }, - { name: "Analytics", path: "/analytics", icon: TrendingUp }, - { name: "Profile", path: "/profile", icon: User }, -]; - return ( - <> - {/* logout modal here, outside of nav so that it overlays everything */} - - {
{/* Logo Section with Hover Animation */} - + D - + DailyForge {/* Desktop Navigation */} - {user && ( + {token && (
{navLinks.map((link) => ( { )} - {!user ? ( + {!token ? ( <> { ) : (