lazy-node-auth
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

lazy-node-auth

MIT license NPM version

Unopinionated auth manager that's good for hackathons & BAD FOR PRODUCTION.

Installation:

npm i lazy-node-auth

Concepts:

With each user account, three properties are stored:

  • The SHA256 password hash (auto-generated).
  • Private props (optional). (Ex. email, address).
  • Public props (optional). (Ex. job title, bio).

The data types that can be stored (as public/private props) are defined in the IPrimitive type:

  • string
  • number
  • boolean
  • array (of accepted types).

Example Usage (Typescript of course):

Import the module:

import LazyNodeAuth from "lazy-node-auth";
const Auth = LazyNodeAuth("auth.store"); // File location.

Import in JS:

const LazyNodeAuth = require("lazy-node-auth").default;
const Auth = LazyNodeAuth("auth.store"); // File location.

Create an account (signup):

const USERNAME = "RameshMondo";
const PASSWORD = "@RMondo123";
 
Auth.register(USERNAME, PASSWORD);

Validate username and password match (login):

const match: boolean = Auth.validate(USERNAME, PASSWORD);    

Check if a username exists:

const exists: boolean = Auth.exists(USERNAME);

Set private props (username & password required):

Auth.setPrivateProps(USERNAME, PASSWORD, {
    phone: ["1", "000", "999", "1234"],
    address: ["The White House", "San Francisco", "CA"]
});

Set public props (username & password required):

Auth.setPublicProps(USERNAME, PASSWORD, {
    firstName: "Ramesh",
    lastName: "Mondo"
});

Manually write to file (not really recommended):

Auth.sync((err: Error) => {
    /* This is the callback function */
    if (!err) console.log("It synced!"); 
})

Get private props (username & password required):

const privateProps = Auth.getPrivateProps(USERNAME, PASSWORD);

Get public props (username required):

const publicProps = Auth.getPublicProps(USERNAME);

Testing:

I was too lazy to use formal unit testing. So I wrote a script to run every function with details logged. Clone the repo, Install deps (npm i), and run the 'tests' : npm test.

Package Sidebar

Install

npm i lazy-node-auth

Weekly Downloads

8

Version

2.0.0

License

MIT

Unpacked Size

21.6 kB

Total Files

11

Last publish

Collaborators

  • raghavm