nabiltntn / loggedin-mixin

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

Home Page:https://atmospherejs.com/tunifight/loggedin-mixin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

https://atmospherejs.com/tunifight/loggedin-mixin


Languages

Language:JavaScript 100.0%