You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+50-10Lines changed: 50 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -79,8 +79,8 @@ export default {
79
79
</script>
80
80
```
81
81
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.
84
84
85
85
Using `hasWarrant` plugin method:
86
86
```vue
@@ -95,7 +95,14 @@ export default {
95
95
protectedInfo: null,
96
96
},
97
97
async created() {
98
-
if (await this.$warrant.hasWarrant("info", "protected_info", "viewer")) {
@@ -145,11 +152,44 @@ import { ProtectedView } from "@warrantdev/vue-warrant";
145
152
export default {
146
153
components: {
147
154
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
+
},
149
165
};
150
166
</script>
151
167
```
152
168
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
+
constisAuthorized=awaitthis.$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
+
153
193
## Notes
154
194
We’ve used a random Client Key in these code examples. Be sure to replace it with your
0 commit comments