Skip to content

SumithRaj05/Authentication-CRUD-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

User-Backend-Api

This is a CRUD (Create, Read, Update, Delete) API for user authentication and email verification, built using Express.js and MongoDB. The API provides endpoints to manage user accounts, including #, login, email verification, JWT authentication and basic user profile operations.

Features

  • User #: Allows new users to create an account by providing a full name, unique email and password.
  • verification mail is sent to user after #
  • User login: Authenticates users for subsequent requests.
  • JWT token is sent after user login.
  • On every request user must send token in header with key as "token".
  • Update user profile: Enables users to update their profile information, such as name, email, mobile number, or password.
  • Delete user account: Allows users to delete their account and associated data from the database.
  • Email Authentication: Sends one time email verification link on #.
  • Use an API testing tool ( Postman ) to interact with the API endpoints.
  • Email verification html files are served by api.

API Endpoints

The following API endpoints are available:

  • GET /profile/userdata : Featches user details from token provided.
  • POST /profile/# : Creates a new user account and sends verification link to provided email.
  • POST /profile/# : Authenticates the user and provides JWT token.
  • PATCH /profile/update : Updates the profile information for the user and returns updated token.
  • DELETE /profile/delete : Deletes the account for the user.
  • GET /verify/:id : Verification Link in email.

JsonWebToken Header Formatting

{
    "token": "jwt-token"
}

Response and Request Body Formatting

#

  • Request
  • {
        "fullname": "user full name",
        "email": "user@gmail.com",
        "password": "user password"
    }
  • Response
  • {
        "status": 200,
        "content": "Email verification link sent"
    }

Login

  • Request
  • {
        "email": "user@gmail.com",
        "password": "user password"
    }
  • Response
  • {
        "status": 200,
        "token": "jwt-token"
    }

Get User

  • Response
  • {
        "status": 200,
        "data": {
            // necessary data
        }
    }

Update

  • Request
  • ( "data" object may contain any information of username, email or password. )

    {
        "data": {
            "fullname": "new-username",
            "email": "new-email",
            "password": "new-password"
        }
    }
  • Response
  • {
        "status": 200,
        "content": "User updated",
        "token": "new-updated-jwt-token"
    }

Delete

  • Response
  • {
        "status": 200,
        "content": "User deleted"
    }

Environment Variables

The following environment variables need to be set for the project to function correctly:

  • `MONGO_URL`: Url of mongoDB database, where data is to be stored.
  • `USERAUTH`: Admin email for nodemailer authentication. Example: `admin@gmail.com`.
  • `PASAUTH`: Application passord of email generated by google. Example: `xxxx xxxx xxxx`.
  • `URL`: IP or DNS name of the server hosted. Example: `http://localhost:8080`.
  • `JWTKEY`: JWT key to create and encrypt json web token.
Make sure to set these variables with appropriate values before running the project.

Contribution

We value and appreciate contributions from the community, whether it's fixing a bug, adding a new feature, improving documentation, or suggesting enhancements.

Releases

No releases published

Packages

No packages published