1.0.0 • Published 4 years ago

@ampraveeen/nestjs-user-management v1.0.0

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

Description

Nestjs user management is npm package (for nestjs) for manage users,rbac & auth for lms project

Requirements

You need to have nestjs app with mogodb database. Setup MongooseModule first.

Installation

$ npm install nest-user-management

How to use

  • In your AppModule file import UserAuthModule from nestjs-user-management and registet it with your configOption in imports
import { UserAuthModule } from 'nest-user-management';
.
.
.
imports: [...,
      UserAuthModule.register({
        authOptions,
        jwtOptions:{
          secret: 'your jwt secret',
          signOptions: { expiresIn: 'jwt validity time' }
        },
        rbacOptions: {
          AppPermissions:'your custom permissions array'
          AppRoles:'your custom assign permissions array'
        }
      })
    ]

provide the cofiguration details as mentioned above.

Now you can access /auth , /users, /rbac APIs provided by package.

First Steps

  1. Create a superadmin user.

  2. now create default permissions.

  3. now create vendor, teacher and student roles.

Setting Permission & Using Guards

  1. Use JwtAuthGuard (from auth module) for setting jwt token authorization to API.

  2. Use OrganizationGuard ( from organization module ) for APIs which need organizationId to complete.

  3. To set permission to your API route use RolesGuard & setRoute (for setting unique api code to your route)

  4. User RolesGuard (from rbac module ) for sverifying role permissions.

import { JwtAuthGuard, RolesGuard  } from 'nest-user-management';

  @Get('')
  @UseGuards(JwtAuthGuard,RolesGuard)
  @RouteCode('get_test_data')// unique api code
  getHello() {
    return this.service.gethello();
  }

Notes

  • If user register as vendor, after registration he needs to create an organization first.

Stay in touch

License

Nest is MIT licensed.