Skip to content

Instantly share code, notes, and snippets.

@francium-lupe
Last active August 29, 2023 13:56
Show Gist options
  • Save francium-lupe/f80dac7eb73be5af783903442a4fd309 to your computer and use it in GitHub Desktop.
Save francium-lupe/f80dac7eb73be5af783903442a4fd309 to your computer and use it in GitHub Desktop.
Node 1
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