-
Notifications
You must be signed in to change notification settings - Fork 6
Examples
Romain Lanz edited this page Oct 17, 2017
·
5 revisions
Let's require both Facades from node-fence.
const { Gate, Guard } = require('@slynova/fence')Then let's define some gate using gate's method.
Gate.define('posts.update', (user, post) => {
return user.id === post.author_id
})
Gate.define('seeGreetings', user => {
return user.id === 1
})Now you are able to call Guard somewhere inside your code to check the authorization of a user.
// We are defining the default User that Guard will use
// when he checks a gate/policy.
Guard.setDefaultUser({ id: 1 })
if (await Guard.allows('seeGreetings')) {
console.log('Hello World!')
}
// ...