TypeScript Express JWT Example https://ts-express-jwt-sg.herokuapp.com/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Sudipto Ghosh 73e9e122df
build only master and dev
10 months ago
.vscode added tests for endpoints and improved coverage 10 months ago
lib fixed something 10 months ago
public revamped exp handling 10 months ago
src fixed something 10 months ago
views added front-end app 10 months ago
.drone.yml build only master and dev 10 months ago
.eslintrc added CI 10 months ago
.gitignore fixed something 10 months ago
.travis.yml build only master and dev 10 months ago
LICENSE.md revamped to jwt api 10 months ago
README.md updated README 10 months ago
package-lock.json fixed something 10 months ago
package.json fixed something 10 months ago
tsconfig.json revamped exp handling 10 months ago

README.md

TypeScript Express JWT Example

Drone (self-hosted) Travis (.com) Codecov

Simple Authentication API using JWT written in TypeScript with SQLite DB.

API

User Registration

Endpoint: POST /api/register

Request Body

  • name: name of the user (required)
  • email: email of the user (required)
  • password: password (plaintext or externally hashed) (required)

Example Response

{
    "user": {
        "id": 1,
        "name": "Awesome User",
        "email": "a@b.com",
        "password": "<INTERNALLY_HASHED_PASSWORD>"
    },
    "access_token": "<ACCESS_TOKEN>",
    "expires_in": 86400
}

User Login

Endpoint: POST /api/login

Request Body

  • email: email of the user (required)
  • password: password (plaintext or externally hashed) (required)

Example Response

{
    "user": {
        "id": 1,
        "name": "Awesome User",
        "email": "a@b.com",
        "password": "<INTERNALLY_HASHED_PASSWORD>"
    },
    "access_token": "<ACCESS_TOKEN>",
    "expires_in": 86400
}

User Deletion

Endpoint: DELETE /api/delete

Request Body

  • email: email of the user (required)
  • password: password (plaintext or externally hashed) (required)

Request Headers

  • Authorization: Bearer <ACCESS_TOKEN> (required)

Example Response

{
    "message": "User <USER_EMAIL> deleted!",
    "access_token": "<ACCESS_TOKEN>",
    "expires_in": 86400
}

User Profile Update

Endpoint: PUT /api/update

Request Body

  • email: email of the user (required)
  • password: password (plaintext or externally hashed) (required)

Either

  • newEmail: new email of the user, OR
  • newName: new name of the user

Request Headers

  • Authorization: Bearer <ACCESS_TOKEN> (required)

Example Response

{
    "user": {
        "id": 1,
        "name": "Awesome User",
        "email": "c@d.com",
        "password": "<INTERNALLY_HASHED_PASSWORD>"
    },
    "access_token": "<ACCESS_TOKEN>",
    "expires_in": 86400
}

Author

Sudipto Ghosh sudipto(at)ghosh(dot)pro

License

Source code distributed under the MIT License.