This project is a user authentication application built using Node.js, Express.js, and Mongoose. It allows users to log in, register, and view their email along with a logout option. If a user does not exist during login, they are redirected to the registration page.
- User Registration
- User Login
- Protected Routes
- Display User Email
- User Logout
- Node.js
- Express.js
- Mongoose
- MongoDB
- EJS (Embedded JavaScript templates)
- bcrypt (for password hashing)
- cookie-parser (for parsing cookies)
- dotenv (for environment variables)
- jsonwebtoken (for JWT authentication)
- Clone the repository:
git clone https://github.com/shashankaz/backend-signup-login.git
cd backend-signup-login
- Install dependencies:
npm install
- Set up environment variables:
Create a .env
file in the root directory and add the following:
PORT=3000
MONGO_URI=your_mongodb_connection_string
Replace your_mongodb_connection_string
with your actual MongoDB connection string.
- Start the application:
npm start
The application will be running on http://localhost:3000
.
- Navigate to
http://localhost:3000/register
- Fill out the registration form and submit.
- Navigate to
http://localhost:3000/login
- Fill out the login form and submit.
- If the user does not exist, you will be redirected to the registration page.
- After logging in, you will be redirected to the profile where you can see your email and a logout button.
- Click the logout button to log out of the application.