Giter Site home page Giter Site logo

otp_jwt_backend's Introduction

User Registration and Authentication API

Introduction

This project is aimed at developing a secure user registration and authentication system using Express.js and MongoDB. It includes APIs for user registration, email verification, user information update, user login, and retrieval of user information using JWT token authentication.

Technologies Used

  • Express.js
  • MongoDB
  • JSON Web Tokens (JWT)
  • Node.js

Setup Instructions

  1. Clone the repository from GitHub.
  2. Navigate to the project directory.
  3. Install dependencies using npm install.
  4. Start the local server using npm run server.

API Endpoints

1. User Registration

  • URL: /api/register
  • Method: POST
  • Request Body:
    • email (string): User's email address
    • password (string): User's password
  • Response:
    • Success: Status 200 OK
    • Error: Status 400 Bad Request

2. Send OTP for Email Verification

  • URL: /api/generateOTP
  • Method: POST
  • Request Body:
    • email (string): User's email address
    • password (string): User's password
  • Response:
    • Success: Status 200 OK
    • Error: Status 400 Bad Request

3.1 Validate User Account

  • URL: /api/verifyOTP
  • Method: POST
  • Request Body:
    • email (string): User's email address
    • otp (string): One-time password sent to the user's email
  • Response:
    • Success: Status 200 OK
    • Error: Status 400 Bad Request

3.2 Update Information

  • URL: /api/updateUser
  • Method: PUT
  • Request Body:
    • email (string): User's email address
    • location (string)
    • age (string)
    • work_Details (string)
  • Response:
    • Success: Status 200 OK
    • Error: Status 400 Bad Request

4. User Login and JWT Token Generation

  • URL: /api/login
  • Method: POST
  • Request Body:
    • email (string): User's email address
    • password (string): User's password
  • Response:
    • Success: JWT token with Status 200 OK
    • Error: Status 401 Unauthorized

Paste the token in header as Baerer token i.e 'Bearer token'

5. Retrieve User Information

  • URL: /api/userinfo
  • Method: GET
  • Request Header:
    • Authorization: Bearer
  • Response:
    • Success: User information with Status 200 OK
    • Error: Status 401 Unauthorized

Screenshots

Attached screenshots of each API from POSTMAN.

MongoDB Schema

const UserSchema = new Schema({
  email: {
    type: String,
    required: true,
    unique: true
  },
  password: {
    type: String,
    required: true
  },
  isVerified: {
    type: Boolean,
    default: false
  },
  location: {
    type: String
  },
  age: {
    type: Number
  },
  work_details: {
    type: String
  }
});

otp_jwt_backend's People

Contributors

vivekanandojha avatar licks-create avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.