Git Product home page Git Product logo

calvarezberrios / generic-api-with-auth Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 4.0 89 KB

A starter nodejs backend project that can get you started with login authentication using JSON Web Tokens and Jest Testing of Endpoints. Can be used for most projects that require user authentication.

JavaScript 100.00%
nodejs-api nodejs-server backend-api authentication-middleware testing-framework jest jsonwebtokens sqlite3 knex postgresql

generic-api-with-auth's Introduction

BackEnd Build Week API Starter

This api is made to work with the project named above built by a team consisting of UI/UX Web, React FrontEnd, and Backend developers


Introduction


This api will provide the resources necessary on the React App to log in, out, and display data for users to use. The complete project is built in a two week period where the team collaborates to get all essential items connected to each other to make one app for the user.

Make sure to add a .env file with at least the following:

    PORT=5000
    NODE_ENV=development
    DATABASE_URL=postgres://postgres:<postgres_password>@localhost:5432/<database_name_in_postgres>

    JWT_SECRET=your secret here... you can convert it to any type of hash online if you like

Convert Secret or anything to hash -> Click Here!

  • This will convert the secret to an MD5 Hash string
  • You can use any hash generator online, just Google Hash Generator



Schema

Users

Fieldname Data Type
id Primary Key - Int - Generated By Database
fname String - Required
lname String - Required
email String - Required
password String - Required - Hashed/Encrypted upon signup



API Endpoints

Deployed to Heroku: Backend Api

Most endpoints receive and return JSON

Authentication

Method Endpoint Description
POST /api/auth/register Creates a user. Requires First Name, Last Name, Email, Username, and Password. Returns the user id, username, and a token.
POST /api/auth/login Logs user in taking the username and password provided. Returns User Id, Username, and Token.


POST /api/auth/register

Receives

{
    "fname": "Test",
    "lname": "Tester",
    "email": "[email protected]",
    "username": "tester",
    "password": "test123"
}

Returns

{
    "user_id": 1,
    "username": "tester",
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NSwibmFtZSI6IkFsaWNlIiwiZW1haWwiOiJhbGljZUBnbWFpbC5jb20iLCJyb2xlcyI6WyJTVFVERU5UIl0sImlhdCI6MTU5MjYxODM4MiwiZXhwIjoxNTkyNjI1NTgyfQ.JCn_0iOCptEmJ7xIKBf4tOPHZanncar719n0mGdHiI8"
}



POST /api/auth/login

Receives

{
    "username": "tester",
    "password": "test123"
}

Returns

{
    "user_id": 1,
    "username": "tester",
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NSwibmFtZSI6IkFsaWNlIiwiZW1haWwiOiJhbGljZUBnbWFpbC5jb20iLCJyb2xlcyI6WyJTVFVERU5UIl0sImlhdCI6MTU5MjYxODM4MiwiZXhwIjoxNTkyNjI1NTgyfQ.JCn_0iOCptEmJ7xIKBf4tOPHZanncar719n0mGdHiI8"
}


Users


Method URL Description
GET /api/users/:id Returns profile info for user by id
PUT /api/users/:id Updates user info for user by id. Users can only update their own data
DELETE /api/users/:id Deletes user for user by id. Users can only delete their own account

GET /api/users/:id

Returns

{
    "id": 1,
    "fname": "Test",
    "lname": "Tester",
    "email": "[email protected]",
    "username": "tester",
    "password": "test123"
}



PUT /api/users/:id

Receives (fields that do not change can be ommitted)

{
    "fname": "Test",
    "lname": "Tester",
    "email": "[email protected]",
    "username": "tester",
    "password": "test123"
}

Returns

{
    "id": 1,
    "fname": "Test",
    "lname": "Tester",
    "email": "[email protected]",
    "username": "tester"
}



DELETE /api/users/:id

Does not receive or return JSON

Returns - Status: 204 = No Content



generic-api-with-auth's People

Contributors

calvarezberrios avatar

Stargazers

 avatar  avatar

Watchers

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