Skip to content

A simple logged-in and roles check minxin to use with mdg:validated-method package

Notifications You must be signed in to change notification settings

nabiltntn/loggedin-mixin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

loggedin-mixin

Install

$ meteor add tunifight:loggedin-mixin

Usage

// Method definition
const method = new ValidatedMethod({
  name, // DDP method name
  mixins : [LoggedInMixin],
  checkLoggedInError: {
    error: 'notLogged',
    message: 'You need to be logged in to call this method',//Optional
    reason: 'You need to login' //Optional
  },
  validate, // argument validation
  run // Method body
});

The LoggedInMixin mixin requires the new checkLoggedInError option which includes the required informations to throw an Error. Note that message and reason are optional.

Roles check

If you are using alanning:roles package in your application, you can add roles check to the basic logged-in check.

For that, you need to add the new checkRoles option which includes the required informations about roles, group and the error to throw.

// Method definition
const method = new ValidatedMethod({
  name, // DDP method name
  mixins : [LoggedInMixin],
  checkRoles: {
    roles: ['admin'],
    group: 'group1', // Optional
    rolesError: {
      error: 'not-allowed',
      message: 'You are not allowed to call this method',//Optional
      reason: 'You are not allowed to call this method' //Optional
    }
  }
  checkLoggedInError: {
    error: 'notLogged',
    message: 'You need to be logged in to call this method',//Optional
    reason: 'You need to login' //Optional
  },
  validate, // argument validation
  run // Method body
});

About

A simple logged-in and roles check minxin to use with mdg:validated-method package

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published