This version of the project uses Email and Password for login.
You can check out the old Username Login version in the feature/username-login
branch!
This project demonstrates the use of HTTP-only cookies to enhance security by preventing client-side JavaScript from accessing cookie data. The project includes a frontend application built with React and Vite, and a backend application using Express and MongoDB.
- User registration and login
- Secure authentication using JWT tokens
- HTTP-only cookies for enhanced security against XSS attacks
- Protected routes accessible only to authenticated users
- Password hashing using bcrypt for secure storage
- Email-based login (instead of username) — See Username Login version here
- Frontend/Backend separation (React + Express.js)
- Error handling and user feedback (success/error alerts)
- React: A JavaScript library for building user interfaces.
- Vite: A build tool that provides a faster and leaner development experience for modern web projects.
- Material-UI: A popular React UI framework.
- Axios: A promise-based HTTP client for the browser and Node.js.
- React Router: A collection of navigational components for React applications.
- Express: A minimal and flexible Node.js web application framework.
- MongoDB: A NoSQL database for storing user information.
- Mongoose: An ODM (Object Data Modeling) library for MongoDB and Node.js.
- bcrypt: A library to help hash passwords.
- jsonwebtoken: A library to create and verify JSON Web Tokens (JWT).
- cookie-parser: A middleware to parse cookies.
- cors: A middleware to enable Cross-Origin Resource Sharing (CORS).
- dotenv: A module to load environment variables from a
.env
file.
- Clone the repository:
git clone https://github.com/TVATDCI/signup-login-render.git
cd signup-login-render
- Install dependencies for both frontend and backend:
npm install
cd client && npm install && npm run dev
- Go to MongoDB Atlas and sign in.
- Create a new project and cluster.
- Add a new database user with proper permissions.
- Allow IP access (0.0.0.0/0 for testing purposes).
- Copy the connection string and update your
.env
file:
MONGO_URI=your_mongodb_atlas_connection_string
JWT_SECRET=your_jwt_secret
PORT=5000
- Start the backend server:
npm start
- Use Postman or cURL to test the API endpoints:
- Signup:
POST http://localhost:5000/api/auth/signup
- Login:
POST http://localhost:5000/api/auth/login
- Get User Profile (Protected Route):
GET http://localhost:5000/api/auth/profile
Ensure everything works correctly before proceeding to deployment.
- Start the backend server:
npm start
- Start the frontend development server:
npm run client-dev
- Open your browser and navigate to
http://localhost:5173
.
.env
.gitignore
client/
.gitignore
public/
src/
components/
Admin/
Admin.jsx
Login/
Login.jsx
Logout/
Logout.jsx
NavBar/
NavBar.jsx
Register/
Register.jsx
index.css
main.jsx
vite.config.js
controllers/
user.js
libs/
db.js
jwt.js
middleware/
auth.js
models/
User.js
package.json
README.md
routes/
userRoute.js
server.js
- Create a new web service on Render.com.
- Connect your GitHub repository to Render.
- Set the build command to:
npm run client-setup
- Set the start command to:
node server.js
- Ensure that the
PORT
environment variable is set to the port Render expects. - Add other necessary environment variables (
MONGO_URI
,JWT_SECRET
, etc.). - Deploy the service.
- Monitor the deployment logs to ensure the build and deployment are successful.
Thanks for smiling ! 😆