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

@zecos/uzer

v0.0.1

Published

`uzer` provides convenience functions for creating and authenticating users.

Downloads

5

Readme

uzer

uzer provides convenience functions for creating and authenticating users.

  • rapidly add user authentication to your app
  • uses sqlite or postgres
  • only stores user email and password
  • passwords hashed using bcrypt

Installation

yarn install --dev uzer

npm i -D uzer

Usage

Initialize the database providing the options:

Sqlite
import { SqliteUzer } from 'uzer'
import sqlite from 'sqlite'

;(async () => {
const uzer = new SqliteUzer({
  tableName: "users",
  validatePassword: password => {
    if (password.length < 10) {
      throw new Error("Password must be at least 10 characters")
    }
    if (!/[!@#$%^&*()].test(password)) {
      throw new Error("Password must contain symbols (!@#$%^&*())")
    }
  },
  sqlite: sqlite.open(":memory:"),
})

await uzer.init()

await uzer.createUser({
  email: "[email protected]",
  password: "Password123",
})
})()
Postgres
import { PostgresUzer } from 'uzer'
import { Pool } from 'pg'

;(async () => {
const uzer = Uzer({
  tableName: "mytable",
  pool: new Pool({
    host: 'localhost',
    user: 'postgres',
    database: 'mydb',
    password: 'password',
    port: 5432,
  })
})

await uzer.init()

await uzer.createUser({
  email: "[email protected]",
  password: "Password123",
})
})()
  • tableName: the name you want for your users table. Defaults to "users" Note: This is useful if you want multiple types of users. For instance, you could have customers and employees. You could have a different user of each type with the same email address.
  • validatePassword: function to use while creating/updating users' passwords Defaults to the passwordValidator function from validatorz
  • postgres
    • pool: pool from the [pg package](https://npmjs.com/pg)
    • sqlite: sqlite db from the [sqlite package](https://npmjs.com/sqlite)

Uzer returns an object with several functions for manipulating/reading the user authentication data. These are documented in the API section.

API

All functions return a promise. Promise is rejected if there is an error.

  • init
    • start the sqlite db
    • () => undefined
  • close
    • close the sqlite db
    • () => undefined
  • createUser
    • creates a user *{email, password} => undefined
  • authenticateUser
    • promise rejects if given invalid credentials
    • {email, password} => undefined
  • getUser
    • returns user's id, email, and hashed password
    • (email) => {id, email, password}
  • getAllUsers
    • returns all users in database
    • () => [{id, email, password}]
  • updateUserEmail
    • updates user's email
    • (curEmail, newEmail) => undefined
  • updateUserPassword
    • updates user's password
    • ({email, password}) => undefined
  • deleteUser:
    • deletes user
    • email => undefined
  • createPasswordResetToken
    • create a token which can be used to set a new password for password recovery
    • email => passwordToken
  • resetPasswordByToken
    • use password from createPasswordResetToken to set the new password
    • ({email, password, token}) => undefined
  • deactivateAccount
    • sets user's active field to false
    • ({email, password}) => undefined
  • reactivateAccount
    • sets user's active field to true
    • ({email, password}) => undefined
  • createEmailVerificationToken
    • creates a token that can be sent to a user's email for verification
    • email => token
  • verifyEmailByToken
    • uses token from createEmailVerificationToken to set user's email_verified status to true
    • ({email, token}) => undefined