Giter Club home page Giter Club logo

authentication's Introduction

Authentication

Open in GitHub Codespaces

The repository contains:

  • Distributed code from eCentennial used to build a server for Authentication.
  • /.devcontainer: Configuration file used by Codespaces to determine operating system.
  • /.vscode: Configuration file used by Codespaces to configure Visual Studio Code settings.
  • /client/.eslintrc: Settings for ESLint included for code consistency and quality.
  • /client/.prettierrc: Settings for Prettier used to format code.
  • package.json and yarn.lock: Defines the application information for Node.js, dependent packages, and the versions needed for each.

Getting Started

Select Open in GitHub Codespaces and then Create codespace. GitHub will prepare the development environment with all the necessary dependencies already installed.

Update .env File

Reference the example provided .env.example to create .env.

MONGODB_URI=mongodb+srv://your_user:your_password@your_cluster.mongodb.net/YourDatabase?retryWrites=true&w=majority&appName=YourApp/yourcollection

Start the Server

After setting up the environment variables, start the server.

yarn start

Test the REST API

  1. Open Thunder Client:

    • Open Thunder Client readily installed in Codespaces by clicking on its icon on the sidebar.
  2. Create a New Request:

    • In Thunder Client, click on the New Request button to start setting up the API request.
    • Enter the API endpoint URL in the URL field: http://localhost:3000/api/users.
    • Select the HTTP method POST from the dropdown next to the URL field.
  3. Set Up Request Body:

    • Click on the "Body" tab, choose the content type, and enter the JSON data.
  4. Send the Request:

    • Click the "Send" button to execute the request. Thunder Client will display the response from the API, including status code, response time, and the body.
  5. Review the Response:

    • On MongoDB Cloud, click on the Database section then Browse Collections.

Example Endpoints

Get all users

  • URL: http://localhost:3000/api/users

  • Method: GET

  • Response:

    [
      {
        "_id": "6685a5c88475a1bf8c42586b",
        "name": "New User",
        "email": "[email protected]",
        "created": "2024-07-03T19:26:00.891Z",
        "updated": "2024-07-03T19:26:00.891Z"
      }
    ]

Resgister a new user

  • URL: http://localhost:3000/api/users

  • Method: POST

  • Body:

    {
      "name": "New User",
      "username": "newuser",
      "email": "[email protected]",
      "password": "password123"
    }
  • Response:

    {
      "message": "Successfully signed up!"
    }

Log a user in

  • URL: http://localhost:3000/auth/signin

  • Method: POST

  • Body:

    {
      "email": "[email protected]",
      "password": "password123"
    }
  • Response:

    {
      "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2Njg1YTVjODg0NzVhMWJmOGM0MjU4NmIiLCJpYXQiOjE3MjAwMzUyOTN9.oUT4Tn16PBaoM2nmko0CePyLpi3E1TnOFxYODi8K-R0",
      "user": {
        "_id": "6685a5c88475a1bf8c42586b",
        "name": "New User",
        "email": "[email protected]"
      }
    }

Fetch a user

  • URL: http://localhost:3000/api/users/668c033d124f409871ef99b8
  • Method: GET
  • Headers:
    Accept: */*
    User-Agent: Thunder Client (https://www.thunderclient.com)
    Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NjhjMDMzZDEyNGY0MDk4NzFlZjk5YjgiLCJpYXQiOjE3MjA0NTIyNzR9.4o_NbVH2pzQoaXsyylhMbmFoJeP70IG3MkDN8IY5YzI
    Accept: */*
    Accept-Encoding: gzip, deflate, br
    Connection: keep-alive
    
  • Response:
    {
        "_id": "668c033d124f409871ef99b8",
        "name": "New User",
        "email": "[email protected]",
        "created": "2024-07-08T15:18:21.846Z",
        "updated": "2024-07-08T15:18:21.846Z",
        "__v": 0
    }

Log a user out

  • URL: http://localhost:3000/auth/signin

  • Method: GET

  • Response:

    {
      "message": "signed out"
    }

authentication's People

Contributors

ttran375 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.