/server

REST API for Kumpulin web

Primary LanguageJavaScriptMIT LicenseMIT

Kumpulin API

Tech Stack

Preparation

Database

Install mysql or mariadb

Google OAuth 2.0

Get GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET from Google Developers Console

Facebook OAuth 2.0

Get FACEBOOK_APP_ID and FACEBOOK_APP_SECRET from Facebook Developers.

Sendgrid API Key

Get SENDGRID_API_KEY from Sendgrid

Installation and Configuration

  1. Run: npm install to install the dependencies
  2. Create database
  3. Edit .env
  4. Run: npm migrate to create the tables into the database

Running

Development

  1. Run: npm run seed to insert demo data into the database
  2. Run: npm run dev to run server

Production

  1. Run: npm run start to run server

API Endpoints

Authentication

Authorization: Bearer jwt.token.here

/auth

Endpoint HTTP Description Body Return
/auth/signup POST Sign up email, password user
/auth/signin POST Sign in email, password user, token
/auth/forgot_password POST Send email including link for reset password page email { success: true }
/auth/reset_password GET Redirect to reset password page if token is still valid - -
/auth/reset_password POST Reset passwod password, token user
/auth/refresh_token POST Refresh JWT token token token
/auth/google GET Sign in using google - -
/auth/google/callback GET Path that users are redirected to after they have authenticated with Google - token
/auth/facebook GET Sign in using facebook - -
/auth/facebook/callback GET Path that users are redirected to after they have authenticated with Facebook - token

/account

Authentication required

Endpoint HTTP Description Body Return
/account/ GET Get current user data - user
/account/change_password POST Change current user password oldPassword, newPassword user

/events

Authentication required

Endpoint HTTP Description Body Return
/events/ GET Get all events data - List of events
/:eventId GET Get event data by id - eventId
/:eventId/details GET Get event details data by id - event details
/:eventId/join POST Update event data by id - { success: true }

JSON Objects returned by API

User

{
  "user": {
    "id": 6,
    "googleId": null,
    "facebookId": null,
    "name": null,
    "email": "Dillon.Johnston@yahoo.com",
    "created_at": "2018-08-31T03:15:14.000Z",
    "updated_at": "2018-08-31T03:15:14.000Z"
  }
}

List of users

{
  "users": [
    {
      "id": 1,
      "googleId": null,
      "facebookId": null,
      "name": "Kali Keeling PhD",
      "email": "Mercedes_Hamill76@gmail.com",
      "created_at": "2018-08-31T03:09:40.000Z",
      "updated_at": "2018-08-31T03:09:40.000Z"
    },
    {
      "id": 2,
      "googleId": null,
      "facebookId": null,
      "name": "Mia Roberts V",
      "email": "Adah_Quigley47@hotmail.com",
      "created_at": "2018-08-31T03:09:40.000Z",
      "updated_at": "2018-08-31T03:09:40.000Z"
    }
  ]
}

JWT Token

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NywiZW1haWwiOiJnaWJyYW5raHJpc25hcHV0cmFAZ21haWwuY29tIiwiaWF0IjoxNTM1Njg4MDA2LCJleHAiOjE1MzYyOTI4MDZ9.jwVZHCsGKb6pLlYR--qJlLAlo8zSdK9H7Nc5tlreTXc"
}