@i-xor/nauth
v1.1.3
Published
NodeJS's permission management framework.
Downloads
73
Maintainers
Readme
NAUTH
NAUTH is a Node.js authentication and permission management framework. It is designed to be simple to use and easy to integrate into any Node.js application.
Node.js 认证与权限管理框架
Quick to use
npm install @i-xor/nauth
pnpm install @i-xor/nauth
yarn add @i-xor/nauth
import { NauthManager } from './manager';
import { NauthConfiguration } from './configuration';
NauthManager.setConfiguration(new NauthConfiguration());
NauthManager.setDB(adapter);
// Check nauth whether it's ready.
NauthManager.check()
Verifier.login(uid);
Test
npm run test
npm run test:coverage
pnpm run test
pnpm run test:coverage
yarn test
yarn test:coverage
Login
const _token = await checkPass(username, password) ? await Verifier.login(username) : null;
const id = await Verifier.loginID(_token);
const token = await Verifier.tokenValue(id);
const user = await Verifier.info(id);
const ctx = await Verifier.ctx(id);
const isLogin = await Verifier.isLogin(id);
await Verifier.logout(id);
Router
RouterMatcher.isMatched('/user/1', '/user/{*path}') ? Verifier.checkLogin(id) : null;
const router = new RouterMatcher();
router.add('/user/:id', async () => {
const id = ctx.params.id;
await Verifier.checkLogin(id);
});
router.add('/admin/:id', async () => {
const id = ctx.params.id;
await Verifier.checkPermission(id, 'user');
});
router.match('/user/1');
Manager
const configuration = NauthManager.configuration;
const db = NauthManager.dbAdapter;
const verifierLogic = NauthManager.getLogic(logicType);