JWTExpressPassport is a simple authentication system built with Express.js, Passport.js, and JWT (JSON Web Tokens). It provides a secure way to authenticate users using JWT tokens stored in cookies.
- User registration with hashed passwords
- User login with JWT token generation and cookie storage
- User logout with cookie deletion
- Protected routes with JWT token verification
- Clone the repository:
git clone <repository-url>
cd JWTExpressPassport
- Install dependencies:
npm install
- Set up environment variables:
Create a .env
file in the root directory and add the following variables:
MONGODB_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret
PORT=5000
Replace your_mongodb_connection_string
and your_jwt_secret
with your actual MongoDB connection string and JWT secret.
- Start the server:
npm start
- Use the following routes to interact with the authentication system:
POST /api/v1/auth/register
: Register a new user.POST /api/v1/auth/login
: Log in with an existing user.POST /api/v1/auth/logout
: Log out the current user.GET /api/v1/auth/profile
: Access the user's profile (protected route).