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

@open-stock/stock-auth-server

v3.8.5

Published

> TODO: description

Downloads

5,725

Readme

@open-stock/stock-auth-server

A simple and powerfull authentication library for Nodejs with user state management. This only works with (https://github.com/BrianPollar/@open-stock/stock-auth-client) the server library. This requires @open-stock/stock-notif-server and @open-stock/stock-universal-server to be installed and initialised.

Features

stock-auth-server implements a full authentication system. It consists of:

Its main features are:

Reliability

The libarary uses standard encryption for data protection:

Simple and convenient API

Sample code:

import expresss from 'expresss';
import { runStockAuthServer, IStockAuthServerConfig } from "@open-stock/stock-auth-server";

const app = expresss;

const config : IStockAuthServerConfig {
  // ...config
}
const { stockAuthRouter } = await runStockAuthServer(config);

app.use(stockAuthRouter);

Installation

// with npm
npm install @open-stock/stock-auth-server

// with yarn
yarn add @open-stock/stock-auth-server

How to use

The following example initialises stock-auth-client and gets the chat client and chat controller instances.

import expresss from 'expresss';
import { runStockAuthServer, IStockAuthServerConfig } from "@open-stock/stock-auth-server";

const app = expresss;

const config : IStockAuthServerConfig {
  // ...config
}
const { stockAuthRouter } = await runStockAuthServer(config);

app.use(stockAuthRouter);

Extra Features

Here are the features of the stock-auth-server library

NOTE

Most of the features below are automatically implememnted by the library. But If you want to use the classes and functions provided by the library, you can do so by importing them from the library. Some of them are elaborated below.

defineAdmin

defineAdmin is a function that is used to define an admin.

usage

import { defineAdmin } from "@open-stock/stock-auth-server";
const adminProps = defineAdmin();

login

login is a function that is used to login a admin.

usage

import { login } from "@open-stock/stock-auth-server";

const res = await login(password, serverKey);

checkIfAdmin

checkIfAdmin is a function that is used to check if a user is an admin.

usage

import { checkIfAdmin } from "@open-stock/stock-auth-server";
const emailPhone = '[email protected]' || '1234567890';
const password = 'password';
const recorgnisewdServerId = 'serverId';
const serverKey = 'serverKey';

const res = await checkIfAdmin(emailPhone, password, recorgnisewdServerId, serverKey);

checkIpAndAttempt

checkIpAndAttempt is a middleware function that is used to check the ip and attempt.

usage

import { checkIpAndAttempt } from "@open-stock/stock-auth-server";
import { apiRouter } from "@open-stock/stock-universal-server";

apiRouter.post('/login', checkIpAndAttempt(), (req, res) => {}));

isTooCommonPhrase

isTooCommonPhrase is a middleware function that is used to check if a phrase is too common.

usage

import { isTooCommonPhrase } from "@open-stock/stock-auth-server";
import { apiRouter } from "@open-stock/stock-universal-server";

apiRouter.post('/signup', isTooCommonPhrase(), (req, res) => {}));

isInAdictionaryOnline

isInAdictionaryOnline is a middleware function that is used to check if a phrase is in a dictionary online.

usage

import { isInAdictionaryOnline } from "@open-stock/stock-auth-server";
import { apiRouter } from "@open-stock/stock-universal-server";

apiRouter.post('/signup', isInAdictionaryOnline(), (req, res) => {}));

generateToken

generateToken is a function that is used to generate a jwt token.

usage

import { generateToken } from "@open-stock/stock-auth-server";
import { Iauthtoken } from "@open-stock/stock-universal";

const authConfig: Iauthtoken = { 
// ...
};
const expiryDate = new Date();
const jwtSecret = 'string'

const token = generateToken(authConfig, expiryDate, jwtSecret);

setUserInfo

setUserInfo is a function that is used to set the user info.

usage

import { setUserInfo } from "@open-stock/stock-auth-server";

const userId: 'string';
const  permissions: Iuserperm = {
// ...
};
const companyId: 'string';
const companyPermissions: IcompanyPerm = {
// ...
};

const details = setUserInfo(userId, permissions, companyId, companyPermissions);

companyAuthRoutes

companyAuthRoutes is a function that is used to get the company auth routes.

usage

import { companyAuthRoutes } from "@open-stock/stock-auth-server";
import { express } from "express";
const app = express();
app.use( '/company', companyAuthRoutes());

// see all routes in the file the router is defined in

authRoutes

authRoutes is a function that is used to get the auth routes.

usage

import { authRoutes } from "@open-stock/stock-auth-server";
import { express } from "express";
const app = express();
app.use('/userauth', companyAuthRoutes());

Documentation

The source code of the website can be found here. Contributions are welcome!

Sponsors

Become a sponsor and get your logo on our README on Github with a link to your site.

License

MIT