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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ryanburnette/authentication

v5.0.0

Published

A really simple Node.js Authentication library.

Downloads

4

Readme

authentication

repo npm

A really simple Node.js Authentication library.

About

This library is not a suggestion of the right way to do anything, or advice on how you should do something. It's just how I start out doing authentication on some of the apps I build.

Configuration

Core

  • users required Provide an Array of user objects. If you have users in a database, or a custom implementation, take a look at users.js. The default implementation is just providing two async functions, all() and find(email). Provide an object with the expected functions and behavior to use your existing user database.
  • signinTimeout Time in milliseconds for a sign in request to expire. This is the time from when a user initiates the sign in process until they must complete it to avoid the sign in epxiring. Defaults to 10 minutes.
  • sessionTimeout Time in milliseconds for a session to expire. This is how long a token is valid for beginning with when it was issued. Sessions won't expire unless this is provided.

Sessions

  • dir If using built-in sessions, this is the directory to keep the session details in. Defaults to ./.authentication/.
  • sessions If built-in sessions is not to be used, override it by providing an object here. Take a look at sessions-fs.js to see what functions must be present and how they should behave.

Email Sending

Configure these options if you are using the built-in email function lib/email.js.

  • name required The name of the app.
  • env Emails are not sent in development. Defaults to development.
  • domain required Domain of the app.
  • proto The protocol of the app. Used by the built-in email delivery function to create signinLink.

These options are passed directly to Nodemailer, so take a look at those docs if you're using the built-in email delivery function.

  • smtp required Nodemailer options
  • smtp.host required SMTP host
  • smtp.port SMTP port
  • smtp.secure SMTP secure (boolean)
  • smtp.user SMTP user
  • smtp.pass SMTP pass

Or pass in your own email function as opts.email.

Tokens

  • signinToken A shorter token that's generated when a user starts the sign in process. This will also serve as the session identifer.
  • authorizationToken A longer token that is generated when a user claims their token.
  • token The token used for authentication.

API

Async functions provided by the returned object that are used in an implementation.

  • signin({ email, attrs }) Start the sign in process. Email the user a signinToken.
  • exchange({ signinToken, attrs, [session] }) Complete the sign in process. Exchange a signinToken for an authorizationToken. Resolves the session and user. Sometimes you're doing things that require looking up the session before you exchange. If you already have the session, you can pass it along.
  • verify(token) Verify a token. Resolves the session and user. Throws errors for all failures. Catch!
  • signout(signinToken) Destroy the session associated with this token.

Error Codes

This library will throw these error codes. Watch for them and reveal to the client what you choose to.

  • ERR_USER_NOT_FOUND User not found.
  • ERR_SIGNIN_EXPIRED Sign In expired.
  • ERR_SESSION_EXPIRED Session expired.
  • ERR_SESSION_NOT_FOUND Session not found.
  • ERR_SESSION_CLAIMED Session already claimed.
  • ERR_INVALID_TOKEN Invalid token.
  • ERR_NOT_CLAIMED This session was never claimed. We should never get this error.