Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nabiltntn/loggedin-mixin
A simple logged-in and roles check minxin to use with mdg:validated-method package
https://github.com/nabiltntn/loggedin-mixin
authentication check meteor-package methods roles
Last synced: 8 days ago
JSON representation
A simple logged-in and roles check minxin to use with mdg:validated-method package
- Host: GitHub
- URL: https://github.com/nabiltntn/loggedin-mixin
- Owner: nabiltntn
- Created: 2016-01-26T14:20:15.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-02-15T13:52:21.000Z (over 8 years ago)
- Last Synced: 2024-10-31T06:51:11.329Z (15 days ago)
- Topics: authentication, check, meteor-package, methods, roles
- Language: JavaScript
- Homepage: https://atmospherejs.com/tunifight/loggedin-mixin
- Size: 6.84 KB
- Stars: 23
- Watchers: 5
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# loggedin-mixin
## Install
```sh
$ meteor add tunifight:loggedin-mixin
```## Usage
```js
// 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.```js
// 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
});
```