Skip to content

Commit 71f40c0

Browse files
committed
Update README
1 parent 4674e91 commit 71f40c0

File tree

1 file changed

+50
-10
lines changed

1 file changed

+50
-10
lines changed

README.md

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ export default {
7979
</script>
8080
```
8181

82-
### `hasWarrant(objectType, objectId, relation)`
83-
`hasWarrant` is a plugin method that returns a `Promise` which resolves with `true` if the user for the current session token has the warrant with the specified `objectType`, `objectId`, and `relation` and returns `false` otherwise. Use it for fine-grained conditional rendering or for specific logic within components.
82+
### `hasWarrant(warrantCheck)`
83+
`hasWarrant` is a plugin method that returns a `Promise` which resolves with `true` if the user for the current session token has the specified `warrants` and returns `false` otherwise. Use it for fine-grained conditional rendering or for specific logic within components.
8484

8585
Using `hasWarrant` plugin method:
8686
```vue
@@ -95,7 +95,14 @@ export default {
9595
protectedInfo: null,
9696
},
9797
async created() {
98-
if (await this.$warrant.hasWarrant("info", "protected_info", "viewer")) {
98+
const isAuthorized = await this.$warrant.hasWarrant({
99+
warrants: [{
100+
objectType: "info",
101+
objectId: "protected_info",
102+
relation: "viewer",
103+
}]
104+
});
105+
if (isAuthorized) {
99106
// request protected info from server
100107
}
101108
}
@@ -115,9 +122,11 @@ import { ProtectedView, authorize } from "@warrantdev/vue-warrant";
115122
116123
export default {
117124
beforeRouteEnter: authorize({
118-
objectType: "secret",
119-
objectIdParam: "secretId",
120-
relation: "viewer",
125+
warrants: [{
126+
objectType: "secret",
127+
objectId: "secretId",
128+
relation: "viewer",
129+
}],
121130
redirectTo: "/",
122131
})
123132
}
@@ -131,9 +140,7 @@ export default {
131140
<div>
132141
<my-public-component/>
133142
<protected-view
134-
:objectType="'myObject'"
135-
:objectId="object.id"
136-
:relation="'view'"
143+
:warrants="warrants"
137144
>
138145
<my-protected-component/>
139146
</protected-view>
@@ -145,11 +152,44 @@ import { ProtectedView } from "@warrantdev/vue-warrant";
145152
export default {
146153
components: {
147154
ProtectedView,
148-
}
155+
},
156+
data: function() {
157+
return {
158+
warrants: [{
159+
objectType: "myObject",
160+
objectId: this.$route.params.objectId,
161+
relation: "view",
162+
}]
163+
};
164+
},
149165
};
150166
</script>
151167
```
152168

169+
## Support for Multiple Warrants
170+
171+
`warrants` contains the list of warrants evaluted to determine if the user has access. If `warrants` contains multiple warrants, the `op` parameter is required and specifies how the list of warrants should be evaluated.
172+
173+
**anyOf** specifies that the access check request will be authorized if *any of* the warrants are matched and will not be authorized otherwise.
174+
175+
**allOf** specifies that the access check request will be authorized if *all of* the warrants are matched and will not be authorized otherwise.
176+
177+
```javascript
178+
// User is authorized if they are a 'viewer' of protected_info OR a 'viewer' of 'another_protected_info'
179+
const isAuthorized = await this.$warrant.hasWarrant({
180+
op: "anyOf",
181+
warrants: [{
182+
objectType: "info",
183+
objectId: "protected_info",
184+
relation: "viewer",
185+
}, {
186+
objectType: "info",
187+
objectId: "another_protected_info",
188+
relation: "viewer",
189+
}]
190+
});
191+
```
192+
153193
## Notes
154194
We’ve used a random Client Key in these code examples. Be sure to replace it with your
155195
[actual Client Key](https://app.warrant.dev) to

0 commit comments

Comments
 (0)