DevTaskFlow Auth Server is a backend authentication service built with Node.js, Express, and MongoDB. It handles user authentication, authorization, and security using JWT tokens for auth. The server provides RESTful API endpoints for user management, login, registration, password recovery, and secure task data access. Integrated with Nodemailer for email-based password resets, it ensures a seamless authentication flow for the DevTaskFlow task management application.
- User Registration and Login - Uses bcrypt to securely store passwords.
- Authentication via JWT - Protect routes with
authenticate
middleware. - Password Recovery - Generates a new password and emails it.
- Task Management - Create, read, update, and delete tasks linked to a user.
- Clone the repository:
git clone https://github.com/art2url/dev-task-flow-auth-server.git cd dev-task-flow-auth-server
- Install dependencies:
npm install
- Create a
.env
file with your credentials:MONGO_URI="<your-mongodb-connection-string>" JWT_SECRET="<your-jwt-secret>" EMAIL_USER="<your-email-username>" EMAIL_PASS="<your-email-password>" PORT=3000 # or your preferred port
- Run the server:
The server starts on
npm start
http://localhost:3000
by default.
βββ server.js # Main server file with routes
βββ package.json # Node dependencies and scripts
βββ .env # Environment variables
βββ ...other configs
- POST
/register
- Registers a user by hashing the provided password and storing user info.
- Request Body:
{ "username": "string", "email": "string", "password": "string" }
- POST
/login
- Authenticates a user using bcrypt, generates a JWT.
- Request Body:
{ "email": "string", "password": "string" }
- POST
/forgot-password
- Generates a random password, hashes it, and emails it to the user.
- Request Body:
{ "email": "string" }
These routes require an
Authorization
header with a valid JWT token:
Authorization: Bearer <token>
-
GET
/tasks
- Fetches all tasks for the authenticated user.
-
POST
/tasks
- Creates a new task for the authenticated user.
- Request Body (example):
{ "title": "string", "description": "string", "priority": "Low | Medium | High", "deadline": "Date", "pinned": "boolean", "completed": "boolean" }
-
PUT
/tasks/:taskId
- Updates an existing task by its
taskId
. - Request Body (fields to update):
{ "title": "string", "description": "string", "priority": "string", "deadline": "Date", "pinned": "boolean", "completed": "boolean" }
- Updates an existing task by its
-
DELETE
/tasks/:taskId
- Deletes a single task by
taskId
.
- Deletes a single task by
-
DELETE
/tasks
- Deletes all tasks for the authenticated user.
- Register a user via
POST /register
. - Login via
POST /login
. A JSON Web Token is returned. - Attach JWT in the
Authorization: Bearer <token>
header for protected routes.
Ensure you have the following variables in your .env
:
MONGO_URI=<your mongodb uri>
JWT_SECRET=<your jwt secret>
EMAIL_USER=<your email user>
EMAIL_PASS=<your email password>
PORT=<port to run on>
- JWT is used for stateless authentication.
- BCrypt for hashing passwords.
- CORS is enabled with either
origin: '*'
or a specific domain.
- Fork the repo.
- Create a feature branch.
- Commit changes.
- Push and open a Pull Request.
MIT License.
For questions or issues, please open an issue or reach out to the maintainers. Thank you for using DevTaskFlow Auth Server!