This repository contains a Node.js application that uses Express and Mongoose to build a simple authentication system that allows users to sign up, login, and logout.
To run this application, follow these steps:
- Clone the repository
- Install the required dependencies by running npm install
- Set up the environment variables required for connecting to MongoDB by creating a .env file with the following fields:
MONGO_USERNAME=<your_mongodb_username>
MONGO_PASSWORD=<your_mongodb_password>
MONGO_DATABASE=<your_mongodb_database>
PORT=<your_preferred_port>
- Start the server by running npm start
This application provides the following API endpoints:
POST /api/v1/auth/signup
: allows users to sign up by providing a username, email, and password. Returns a JWT token that is saved in a cookie.POST /api/v1/auth/login
: allows users to log in by providing their username and password. Returns a JWT token that is saved in a cookie.GET /api/v1/auth/logout
: logs the user out by clearing the JWT token saved in the cookie.GET /page
: a sample authenticated route that requires a valid JWT token to access.
This application uses the following dependencies:
- express
- mongoose
- body-parser
- cookie-parser
- express-validator
- jsonwebtoken
- bcrypt
- validator