npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

awesome-auth-client

v0.0.44

Published

Authenticating, awesomely

Readme

Overview

The client library for awesome-auth used to register and authenticate users and securely connect to endpoints via websocket. It consists of two classes, AwesomeAuth and AuthSocket.

  • AwesomeAuth is used to check authentication status, get info about the current user and register a new user to your application.
  • AuthSocket is used to securely make websocket calls to your http or websocket endpoints.

Get the javascript client

The javascript client is available on npm. Browserify is recommended.

npm install awesome-auth-client

Other options include manually pulling down the most recent release from the repo or referencing the hosted latest version. Include the AwesomeAuth javascript client in your web page to make the AwesomeAuth and AuthSocket modules available.

<script src="awesome-auth.js"></script>

Authentication status

To check user authentication status and identify the current user, create a new instance of the AwesomeAuth object and pass it an options JSON object.

new AwesomeAuth(opts)

  • appName - the name of your mapping file
  • onAuthStatusChange - function that is called with the authentication status when the user's authentication status changes.
    • result.user - If the user has confirmed, this will populated with the user defined in the getUserInfo function
    • result.status - Contains a string representing a failure to authenticate. May be 'user-not-found' or 'unconfirmed'.
    • result.error - If there's a system error during processing
var awesomeAuth = new AwesomeAuth({appName: 'pocket', onAuthStatusChange: function(result){
    if (result.user){
        console.log("Logged in user:", result.user)
        window.currentUser = result.user
    }
    else if (result.status) {
        console.log("Need to register or confirm registration", result.status)
    }
    else if (result.error) {
        console.log("System error", result.error)
    }
}});

Registration

awesomeAuth.register('[email protected]', function(err, token){
    if (err) console.log("err", err);
    if (token) console.log("token", token);
});
awesomeAuth.register({email: '[email protected]', customerName: "Bain", person_id: 1594}, function(err, token){
    if (err) console.log("err", err);
    if (token) console.log("token", token);
}));

This registers a user to the system and sends them a confirmation email. The optional callback function can report that a token was generated and sending an email has been attempted.

AwesomeAuth will continuously poll until they have clicked the link in the email. Once they have confirmed, the onAuthStatusChange callback will return the full user defined in the getUserInfo function.

The data passed to register gets sent to the getUserInfo function, so include anything you need to identify this user.

Resend confirmation

If a user misses the initial confirmation email, they can self-serve and trigger the sending of another.

awesomeAuth.resendConfirmation(function(err){
    if (err) {
        console.log("Error while sending confirmation email", err);
    } else {
        console.log("Confirmation email sent!");
    }
});

Log out

Logging a user out destroys their token. They have to re-register to get back into the system.

awesomeAuth.logOut();

This will trigger the onAuthStatusChange callback with the status "user-log-out". ###Using the authorized socket To initialize, create an instance of AuthSocket and pass in the options object to the constructor.

var opts = {
    appName: 'pocket',
    urls: ["http://query.glgroup.com/epiquery/"]
};

var mySocket = new AuthSocket(opts);
opts
  • appName- name of the app, matching the name of the mapping file.

  • urls - array of urls (protocol and hostname only) to which you want to connect. The host names of the url(s) specified here must match the hosts names specified in the mapping file validHosts property. If your destination has multiple deployments you can specify them all here ("http://east.glgresearch.com/myDest/", "http://west.glgresearch.com/myDest/", etc)

After it has been created, it behaves exactly like a normal websocket. All of the normal Websocket events are exposed on the AuthSocket:

mySocket.onerror = function(error){
    console.log(error)
};

mySocket.onmessage = function(message) {
    console.log("Message from destination server", message)
};

mySocket.onclose = function(event){
    console.log("Connection closed")
};

mySocket.onopen = function(){
    console.log("Connection opened", socket.currentUser)
};

###Sending a message to an HTTP endpoint

HTTP messages will use the send method on the socket and pass an options object.

options verb - HTTP method path - the path to your destination relative to the url(s) provided when creating the socket callback - function that handles results from your call

var opts = {
    verb: 'GET',
    path: 'person/getPersonByLoginName.mustache?Login=glgroup\\khughes'
    callback: function(results) {
        console.log("Here are my results!", results)
    }
}
mySocket.send(opts);

Working offline

There's a development mode that you can use to work completely disconnected from AwesomeAuth. You can use it to fake out a user and to communicate with WebSocket and HTTP servers.

Please note, it has limited functionality. You can't register or log out and it's not performing any authentication. It also doesn't connect to basic auth protected services.

Here's an example of faking out a user.

var myUser = {
  name: "Nick Swarr",
  email: "[email protected]",
  id: 123456
};
  
var awesomeAuth = new AwesomeAuth({user: myUser, authenticationCallback: function(result){
  console.log("Just got my user back!", result.user);
}});

Here's how you set up a local socket.

var authSocket = new AuthSocket({localDev: true, urls: ["ws://localhost:5555/"]});
authSocket.send("This talks directly to my socket server")
``