Skip to content

Commit bcfad65

Browse files
authored
v0.0.4: Add WARRANT_IGNORE_ID constant (#3)
1 parent 0ca90e4 commit bcfad65

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,22 @@ if (await warrant.isAuthorized("store", storeId, "edit")) {
5757
}
5858
```
5959

60+
**NOTE:** To ignore the `objectId` when performing authorization calls using `isAuthorized`, you can pass the constant `WARRANT_IGNORE_ID`. You must have a corresponding warrant that grants access to **ANY** user on the given `objectType` for this check to succeed.
61+
```js
62+
import { Client as WarrantClient, WARRANT_IGNORE_ID } from "@warrantdev/warrant-js";
63+
64+
// A valid session token is required to initialize the Client
65+
const warrant = new WarrantClient('client_test_f5dsKVeYnVSLHGje44zAygqgqXiLJBICbFzCiAg1E=', sessionToken);
66+
67+
//
68+
// Example Scenario:
69+
// An e-commerce website where Store Owners can edit their own Store's info
70+
//
71+
if (await warrant.isAuthorized("store", WARRANT_IGNORE_ID, "edit")) {
72+
// Carry out logic to allow user to edit a Store
73+
}
74+
```
75+
6076
We’ve used a random Client Key in these code examples. Replace it with your
6177
[actual publishable Client Key](https://app.warrant.dev) to
6278
test this code through your own Warrant account.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@warrantdev/warrant-js",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"description": "JavaScript Library to Use Warrant in Client Applications",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
export const API_URL_BASE = "https://api.warrant.dev";
22
export const API_VERSION = "v1";
3+
4+
export const WARRANT_IGNORE_ID = "WARRANT_IGNORE_ID";

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { default as Client } from "./Client";
2+
export { WARRANT_IGNORE_ID } from "./constants";

0 commit comments

Comments
 (0)