Giter Club home page Giter Club logo

socket-io-namespace-events-app's Introduction

Socket.io app with dynamic namespaces

Allow clients to subscribe to transactions specific namespaces

A transaction can be:

  • declined
  • completed
  • cancelled

Authentication

The endpoints are protected using JWT base authentication. Provide the following env variables in a .env file on deployment.

ACCESS_TOKEN_SECRET=
REFRESH_TOKEN_SECRET=
ACCESS_KEY=

Use the auth-server to handle authentication such as:

  • login log in
  • logout log out
  • token generate new token

Login can be done either using an accessKey matching a secret ACCESS_KEY env var (for Admin users) or via name and password for client users.

A placeholder verifyUser({ name, password }) function is supplied that must be customized to do proper verification, such as by lookup in a database.

The JWT token is expected to be passed as a Bearer token in the authorization header

The auth server is set to run on port 4000

API endpoints

Cancelled transaction

POST /cancelled transaction

{
    "clientId": "xyz", 
    "payload": {
        // as you wish
    }
}

Will emit cancelled event with payload to socket for that client

Denied transaction

POST /denied

{
    "clientId": "xyz", 
    "payload": {
        // as you wish
    }
}

Will emit denied event with payload to socket for that client

Completed transaction

POST /completed

{
    "clientId": "xyz", 
    "payload": {
        // as you wish
    }
}

Will emit completed event with payload to socket for that client

Add client

POST /client

{
    "clientId": "xyz", 
    "payload": {
        "id": "xyz",
        "name": "Xyz",
        "subscriptions": ["cancelled"]
    }
}

Remove client

DELETE /client?id=xyz

Removes client from server and disconnects all sockets for that client

Add client event socket

POST /event

{
    "clientId": "xyz", 
    "eventName": "completed"
}

Remove client event socket

DELETE /event?clientId=xyz&eventName=completed

Removes client from server and disconnects all sockets for that client

socket-io-namespace-events-app's People

Watchers

Kristian Mandrup 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.