oth-jen
v1.0.0
Published
## Overview
Downloads
6
Maintainers
Readme
My Node Authentication Bundler
Overview
This API provides user authentication and management functionalities. Below is a detailed explanation of the routes available in the application, along with instructions on configuring necessary API keys and environment variables for a successful setup.
Routes
User Authentication
Register User
- Endpoint:
POST /api/register
- Description: Registers a new user in the application.
- Request Body:
{ "username": "string", "email": "string", "password": "string" }
- Endpoint:
Login User
- Endpoint:
POST /api/login
- Description: Authenticates a user and returns a JWT token.
- Request Body:
{ "email": "string", "password": "string" }
- Endpoint:
Logout User
- Endpoint:
POST /api/logout
- Description: Logs out the user by invalidating the JWT token.
- Middleware: Requires authentication.
- Endpoint:
Forgot Password
- Endpoint:
POST /api/forgot-password
- Description: Initiates the password reset process by sending an email to the user.
- Request Body:
{ "email": "string" }
- Middleware: Requires authentication.
- Endpoint:
Reset Password
- Endpoint:
POST /api/reset-password
- Description: Resets the user's password using a token sent via email.
- Request Body:
{ "token": "string", "newPassword": "string" }
- Middleware: Requires authentication.
- Endpoint:
SMS Verification
Send SMS OTP
- Endpoint:
POST /api/send-otp
- Description: Sends an OTP (One-Time Password) to the user's registered phone number for verification.
- Endpoint:
Verify OTP
- Endpoint:
POST /api/verify-otp
- Description: Verifies the OTP sent to the user's phone number.
- Endpoint:
User Profile
- Get Single User
- Endpoint:
GET /api/:id
- Description: Retrieves the profile of a user by their ID.
- Middleware: Requires authentication.
- Endpoint:
Configuration
Before running the application, make sure to set up your environment variables. You can create a .env
file in the root of your project with the following keys:
# JWT Secret for signing tokens
JWT_SECRET=your_jwt_secret
# Email configuration
[email protected]
EMAIL_PASS=your_email_password
# Twilio configuration
TWILIO_ACCOUNT_SID=your_twilio_account_sid
TWILIO_AUTH_TOKEN=your_twilio_auth_token
# MongoDB connection string
MONGO_URI=mongodb://localhost:27017/mydatabase
Important Notes
- JWT Secret: This is crucial for token generation and validation. Ensure this is a strong, random string.
- Email Configuration: Use your actual email credentials for sending password reset emails.
- Twilio Configuration: Required if you are using Twilio for SMS services. Make sure to sign up for a Twilio account and obtain your
Account SID
andAuth Token
. - MongoDB URI: If you're using a local MongoDB instance, the default connection string will suffice. For cloud databases, replace it with your connection string.
Running the Application
After configuring your environment variables, run the following commands to install dependencies and start the server
plaintext
npm install
npm start
Ensure that you have MongoDB running (either locally or remotely) to connect to the database successfully.
License
This project is licensed under the MIT License - see the LICENSE file for details.
### Usage
- Save this content to a file named `README.md` in the root directory of your project.
- Make sure to update the **License** section if your project uses a different license.
Let me know if you need any further adjustments!