3.8.5 • Published 3 days ago

@open-stock/stock-auth-server v3.8.5

Weekly downloads
-
License
ISC
Repository
-
Last release
3 days ago

@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@mail.com' || '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

3.7.5

4 days ago

3.7.4

4 days ago

3.7.3

4 days ago

3.7.9

3 days ago

3.7.8

3 days ago

3.7.7

4 days ago

3.7.6

4 days ago

3.8.0

3 days ago

3.8.4

3 days ago

3.8.3

3 days ago

3.8.2

3 days ago

3.8.1

3 days ago

3.8.5

3 days ago

3.7.2

7 days ago

3.6.9

8 days ago

3.7.1

8 days ago

3.7.0

8 days ago

3.6.8

8 days ago

3.6.7

9 days ago

3.6.6

10 days ago

3.6.5

10 days ago

3.6.4

12 days ago

3.6.3

15 days ago

3.6.2

17 days ago

3.6.1

17 days ago

3.6.0

17 days ago

3.5.7

17 days ago

3.5.6

17 days ago

3.5.9

17 days ago

3.5.8

17 days ago

3.5.3

18 days ago

3.5.2

18 days ago

3.5.1

18 days ago

3.5.0

18 days ago

3.5.5

18 days ago

3.5.4

18 days ago

3.4.4

18 days ago

3.4.3

18 days ago

3.4.2

18 days ago

3.4.1

18 days ago

3.4.8

18 days ago

3.4.7

18 days ago

3.4.6

18 days ago

3.4.5

18 days ago

3.4.9

18 days ago

3.3.9

22 days ago

3.3.8

22 days ago

3.3.7

22 days ago

3.2.6

22 days ago

3.2.9

22 days ago

3.2.8

22 days ago

3.2.7

22 days ago

3.4.0

22 days ago

3.3.1

22 days ago

3.3.0

22 days ago

3.3.5

22 days ago

3.3.4

22 days ago

3.3.3

22 days ago

3.3.2

22 days ago

3.2.4

24 days ago

3.2.2

28 days ago

3.2.3

28 days ago

3.2.1

29 days ago

3.2.0

29 days ago

3.1.3

29 days ago

3.1.2

29 days ago

3.1.1

29 days ago

3.1.0

29 days ago

3.1.7

29 days ago

3.1.6

29 days ago

3.1.5

29 days ago

3.1.4

29 days ago

3.1.9

29 days ago

3.1.8

29 days ago

3.0.4

29 days ago

3.0.8

29 days ago

3.0.7

29 days ago

3.0.6

29 days ago

3.0.9

29 days ago

3.0.3

30 days ago

2.8.1

1 month ago

2.8.0

1 month ago

3.0.2

1 month ago

3.0.1

1 month ago

2.9.2

1 month ago

2.7.4

1 month ago

2.9.1

1 month ago

2.7.3

1 month ago

2.9.4

1 month ago

2.9.3

1 month ago

2.7.5

1 month ago

3.0.0

1 month ago

2.9.6

1 month ago

2.7.8

1 month ago

2.9.5

1 month ago

2.7.7

1 month ago

2.9.0

1 month ago

2.7.2

1 month ago

2.7.1

1 month ago

2.8.3

1 month ago

2.8.2

1 month ago

2.8.5

1 month ago

2.8.4

1 month ago

2.8.7

1 month ago

2.8.6

1 month ago

2.8.9

1 month ago

2.8.8

1 month ago

2.7.0

1 month ago

2.6.9

1 month ago

2.6.8

1 month ago

2.6.7

1 month ago

2.6.6

1 month ago

2.6.1

2 months ago

2.6.3

2 months ago

2.6.2

2 months ago

2.6.5

2 months ago

2.6.4

2 months ago

2.6.0

2 months ago

2.5.8

2 months ago

2.5.7

2 months ago

2.5.9

2 months ago

2.5.6

2 months ago

2.5.5

2 months ago

2.5.0

2 months ago

2.5.2

2 months ago

2.5.1

2 months ago

2.5.4

2 months ago

2.5.3

2 months ago

2.4.8

5 months ago

2.4.1

5 months ago

2.4.3

5 months ago

2.4.2

5 months ago

2.4.5

5 months ago

2.4.4

5 months ago

2.4.7

5 months ago

2.4.6

5 months ago

2.4.0

5 months ago

2.3.2

6 months ago

2.3.6

6 months ago

2.3.5

6 months ago

2.3.7

6 months ago

2.3.1

6 months ago

2.3.0

6 months ago

2.1.2

7 months ago

2.0.2

8 months ago

2.0.4

8 months ago

2.2.5

6 months ago

2.0.7

8 months ago

2.2.4

6 months ago

2.0.6

8 months ago

2.0.8

8 months ago

2.1.0

8 months ago

2.0.1

8 months ago

2.0.0

10 months ago

2.2.9

6 months ago

2.2.8

6 months ago

1.4.5

11 months ago

1.3.4

11 months ago

1.4.0

11 months ago

1.3.3

11 months ago

1.3.1

11 months ago

1.3.0

11 months ago

1.2.6

11 months ago

1.2.5

11 months ago

1.2.4

11 months ago

1.2.2

11 months ago

1.1.4

12 months ago

1.1.3

12 months ago

1.1.2

12 months ago

1.1.1

12 months ago

1.1.0

12 months ago

1.0.1

1 year ago

1.0.0

1 year ago