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

fauna-auth

v1.1.3

Published

Library for user management backed by FaunaDB

Downloads

11

Readme

Fauna Auth

A library for user authentication backed by FaunaDB

Installation

# npm
npm i --save fauna-auth

#yarn
yarn add fauna-auth

Setup

There are a few preliminary steps.

  1. Create an account at fauna.com
  2. Create a database
  3. Inside the database you just made, create two collections: users and tokens.
  4. Create three indexes.
    1. One called "username" for the users collection with "data.username" as the term.
    2. One called "tokens" for the tokens collection with "data.refreshTokens" as the term.
    3. One called "byId" for the tokens collection with "data.userId" as the term.
  5. Create a new key for your database.
  6. Create two secrets (long, preferably random strings) for signing jwt tokens.
    1. One for access tokens.
    2. Another for refresh tokens.

Note: Please do not commit your key to github. All the examples below will be using environment variables.

Now that you have your key and your secrets, you can initialize the library.

const initAuth = require('./index')

const FaunaAuth = initAuth({
  dbSecret: process.env.DB_SECRET,
  accessSecret: process.env.ACCESS_SECRET,
  refreshSecret: process.env.REFRESH_SECRET,
  tokenDuration: 1000 * 60 * 15,
})

And finally, you can manage and authenticate users.

// Create a user
const newUser = await FaunaAuth.create('username', 'password', { some: 'data' })

// Update a user
const updatedUser = await FaunaAuth.update(existingUser.id, { more: 'data' })

// Change a user's password
const updatedUser = await FaunaAuth.changePassword(existingUser.id, 'newPassword')

// Delete a user
await FaunaAuth.delete(updatedUser.id)

// Authenticate a user
const user = await FaunaAuth.authenticate('username', 'password')

// Create tokens
const { accessToken, refreshToken } = await FaunaAuth.createTokens(user)

// Verify access tokens
const verifiedUser = await FaunaAuth.verify(accessToken)

// Refresh tokens
const { accessToken, refreshToken } = await FaunaAuth.refreshToken(refreshToken)

// Delete refresh tokens when the user manually logs out
await FaunaAuth.deleteRefreshToken(refreshToken)

// Or
await FaunaAuth.deauthenticate(user)

Todo

  • Social Authentication