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

just-login-core

v2.0.1

Published

Handles the authentication at the database level for other just login modules

Downloads

17

Readme

just-login-core

Build Status

Handles tokens for just-login.

Example

var JustLoginCore = require('just-login-core')
var db = require('level-mem')()
var core = JustLoginCore(db)

API

var Core = require('just-login-core')

var core = JustLoginCore(db[, options])

  • db is expecting a levelup database.
  • options is an object that holds the (gasp) options!
    • tokenGenerator is expecting a function that returns an unique string each time it is called. This is used for token generation. Defaults to a UUID generator.
    • tokenTtl is a number in milliseconds of a token's Time To Live (TTL). Defaults to 5 minutes.
    • tokenTtlCheckIntervalMs is a number in milliseconds of the ttl's check interval. (See tiny-level-ttl, checkInterval.) Defaults to 10 seconds.
  • Returns core.

core

It emits some events and has a few methods:

core.beginAuthentication(sessionId, contactAddress[, cb])

Starts the authentication process by emitting the 'authentication initiated' event with a token and the contact address.

Something else must listen for the event, and send a message to the user. See core events for more information.

  • sessionId is a string of the session id that is trying to get authenticated.
  • contactAddress is string of the user's contact info, (usually an email address).
  • cb is a function with the following arguments:
    • err is an Error object or null.
    • authReqInfo is an object with the authentication request information. The object is identical to the object emitted in the event, with the following properties:
      • contactAddress is a string with the contact address.
      • token is a string of the token.
  • Emits core.on('authentication initiated', function (authReqInfo) { ... })
core.beginAuthentication('session id', '[email protected]', function (err, authReqInfo) {
	if (!err) {
		console.log(authReqInfo.token) //logs the token
		console.log(authReqInfo.contactAddress) //logs: "[email protected]"
	}
})

core.authenticate(token[, cb])

Authenticates the token, and calls back with the session id and contact address associated with that token. Then the token and it's associated data is deleted. A token can only be authenticated once.

  • token is a string of the token that is trying to get authenticated.
  • cb is a function with the following arguments:
    • err is an Error object or null.
    • credentials is null is the user is not authenticated, and is an object if they are authenticated:
      • contactAddress is a string of their contact address.
      • sessionId is a string of their session id.
  • Emits core.on('authenticated', function (credentials) { ... })
core.authenticate('the token', function(err, credentials) {
	if (!err) {
		console.log(credentials.contactAddress + ' is now logged in! Congratulations!')
	} else {
		console.log('Sorry, for some reason you are not logged in.')
	}
})

core events

authentication initiated

Emitted when beginAuthentication() is called. (Which should be when the user clicks the "login" button.)

core.on('authentication initiated', function (authReqInfo) {
	console.log(authReqInfo.contactAddress)
	console.log(authReqInfo.token)
})

(You can use just-login-emailer to catch this event.)

authenticated

Emitted when core.authenticate() is successful.

core.on('authenticated', function (credentials) {
	console.log(credentials.contactAddress)
	console.log(credentials.sessionId)
})

Install

Install with npm:

npm install just-login-core

License

VOL