Last active
August 29, 2023 13:56
-
-
Save francium-lupe/f80dac7eb73be5af783903442a4fd309 to your computer and use it in GitHub Desktop.
Node 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Oso } from 'oso'; | |
class User { | |
constructor(roles) { | |
this.roles = roles; | |
} | |
} | |
class Vehicle { | |
constructor(id) { | |
this.id = id; | |
} | |
} | |
const oso = new Oso(); | |
oso.registerClass(User); | |
oso.registerClass(Vehicle); | |
await oso.loadFiles(['main.polar']); | |
const vehicle1 = new Vehicle(1); | |
const vehicle2 = new Vehicle(2); | |
const user = new User([{ name: 'booked-user', resource: vehicle1 }]); | |
// Succeeds | |
await oso.authorize(user, 'security', vehicle1); | |
// Throws "Oso NotFoundError" | |
await oso.authorize(user, 'updateModifiedUsers', vehicle2); | |
// Throws "Oso NotFoundError" | |
await oso.authorize(user, 'security', vehicle2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment