Skip to content

Muhammad-div/finance-app-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Certainly! Here's a sample README file to explain how to use your user authentication API. You can modify and expand upon it as needed:

User Authentication API README

This is a user authentication API built with Node.js, Express, MongoDB, and JWT token authentication. It provides user registration, login, and user profile features, along with email confirmation functionality.

Prerequisites

Before using this API, ensure you have the following prerequisites installed:

  • Node.js (version 14 or higher)
  • npm or yarn
  • MongoDB (and a running database)
  • An email service account (e.g., Gmail) for sending email confirmations

Installation

  1. Clone the repository to your local machine:

    git clone https://github.com/yourusername/user-auth-api.git
  2. Navigate to the project directory:

    cd user-auth-api
  3. Install the project dependencies:

    npm install
    # or
    yarn install
  4. Configure the environment variables:

    • Create a .env file in the project root and define the following variables:

      • MONGODB_URI: Your MongoDB database URI.
      • EMAIL_SERVICE: Your email service provider (e.g., 'Gmail').
      • EMAIL_USER: Your email service account username.
      • EMAIL_PASS: Your email service account password.
      • JWT_SECRET: A strong and secure secret key for JWT token generation.
      • PORT: The port on which the API will run (default: 3000).
  5. Start the server:

    npm start
    # or
    yarn start

API Endpoints

User Registration

  • Endpoint: POST /auth/register
  • Request Body:
    • name (string): User's name
    • email (string): User's email
    • password (string): User's password
  • Response:
    • 201 Created: User registered successfully (with JWT token)
    • 400 Bad Request: Invalid request
    • 409 Conflict: Email already in use

User Login

  • Endpoint: POST /auth/login
  • Request Body:
    • email (string): User's email
    • password (string): User's password
  • Response:
    • 200 OK: Login successful (with JWT token)
    • 401 Unauthorized: Invalid password
    • 404 Not Found: User not found

Get User Profile

  • Endpoint: GET /user/profile
  • Headers:
    • Authorization (string): JWT token obtained during registration or login
  • Response:
    • 200 OK: User profile data
    • 401 Unauthorized: Invalid token
    • 404 Not Found: User not found

Protected Route Example

  • Endpoint: GET /auth/protected
  • Headers:
    • Authorization (string): JWT token obtained during registration or login
  • Response:
    • 200 OK: Access granted to protected route
    • 401 Unauthorized: Invalid token

User Confirmation Email

The API is configured to send a confirmation email after user registration. Make sure to configure your email service provider settings and email content in the emailService.js file.

Contributing

If you would like to contribute to this project or report issues, please feel free to create a pull request or an issue on the project's GitHub repository.

License

This project is licensed under the MIT License - see the LICENSE file for details.


Feel free to adapt and expand this README to suit your project's specific requirements and provide more detailed information about your API and its usage.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors