Dexie.js icon indicating copy to clipboard operation
Dexie.js copied to clipboard

Struggling with permissions and roles and users

Open phil-w opened this issue 8 months ago • 20 comments

I'm struggling with Dexie Cloud, although I've been using Dexie itself over a number of years.

I'm going to need user roles and access control based on that, and I can see some of that possibly in the API, although I'm not sure my use case will work with Dexie Cloud or not. There's a conceptual level of documentation for the Cloud stuff which I've either not found or not understood, so far.

I'm using Sveltekit.

Anyway, one thing I found in the reference function list is db.cloud.permissions which sounds like I will need at some point, and perhaps it will help me sleuth it out.

But what does this code below mean? I just have a database like an old style Dexie database but with the stuff from the documents applied to it to make it Cloud. What is databaseObject and how do I make one?

// When table is not mapped to a DexieCloudEntity subclass:
const o = db.cloud.permissions("friends", databaseObject);

I don't recall mapping anything to anything, but databaseObject is obviously going to need to be set. What is a "database object", why do I need it, what is the relationship between that and a collection "friends"? It says it returns the following:

export interface PermissionChecker {
  add(...tableNames: string[]): boolean;
  update(...props: string[]): boolean;
  delete(): boolean;
}

I'm not sure what sense that makes to me. "add" "update" and "delete" look understandable, so I guess it's a list of permissions. Why does it have table names in it (I'm passing the table/ collection name in, right?) What's the "thing" it's checking the permissions of, exactly? The current user, I suppose?

I wonder if, say, you just had followed the install instructions for Dexie Cloud, and were not using React.... what's a minimal code I'd need to read whatever these permissions are, and is there an example I've not found which does that?

phil-w avatar Jun 24 '24 08:06 phil-w