@horwood/socket-authenticator
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

@horwood/socket-authenticator

This is a Node.js library that provides implementations for @horwood/socket-server's SocketAuthenticator class. Currently MongoSocketAuthenticator is the only implementation available and, as the name suggests, uses a MongoDB instance to handle authentication.

Getting Started

It can be installed through the NPM registry by using the following command:

$ npm install @horwood/socket-authenticator

To make best use of it, it is also recommended to install @horwood/socket-server.

Usage

It is fairly simple to make use of. All it requires is for MongoSocketAuthenticator to be passed to SecureSocketServer's authenticator function. Once this is done, the server will delegate the handling of authentication events to your authenticator. It's also important to note that in order for MongoSocketAuthenticator to work, the application must have an active connection to MongoDB.

import { SecureSocketServer} from '@horwood/socket-server';
import { MongoSocketAuthenticator } from '@horwood/socket-authenticator';
import { connect } from 'mongoose';

connect('mongodb://localhost/database_name').then(() => {
  new SecureSocketServer().authenticator(new MongoSocketAuthenticator()).on('connection').subscribe(socket => {
    // handle socket
  });
});

Dependents (0)

Package Sidebar

Install

npm i @horwood/socket-authenticator

Weekly Downloads

0

Version

1.0.4

License

ISC

Unpacked Size

16.3 kB

Total Files

28

Last publish

Collaborators

  • lnh