brianmmdev
brianmmdev5mo ago

Where does `wrapDatabaseReader` come from?

I'm following this post to create some customer query and mutation handlers and this article makes mention of wrapDatabaseReader and wrapDatabaseWriter but I'm not seeing where those functions are available from?
Customizing serverless functions without middleware
Re-use code and centralize request handler definitions with discoverability and type safety and without the indirection of middleware or nesting of wr...
7 Replies
jamwt
jamwt5mo ago
GitHub
convex-helpers/convex/lib/withUser.ts at main · get-convex/convex-h...
A collection of useful code to complement the official packages. - get-convex/convex-helpers
jamwt
jamwt5mo ago
GitHub
convex-helpers/packages/convex-helpers/server/rowLevelSecurity.ts a...
A collection of useful code to complement the official packages. - get-convex/convex-helpers
brianmmdev
brianmmdevOP5mo ago
Thanks Jamie! I love the pattern described in this article where the user record gets injected into the context. Regarding the rules described in the article, is there a way to simply allow all operations and I can apply my own security logic in the wrapped query? Any example of documentation of how rules is constructed would be very helpful, as that seems to be missing from the article and I cant find anything in the convex-helpers repo. I think I got a working example of what rules would look like but it seems to require a table name as the object keys.
const rules = {
tableName1: {
read: async () => {
return true;
},
modify: async () => {
return true;
},
insert: async () => {
return true;
},
},
};

const db = wrapDatabaseReader({ user }, ctx.db, rules);
const rules = {
tableName1: {
read: async () => {
return true;
},
modify: async () => {
return true;
},
insert: async () => {
return true;
},
},
};

const db = wrapDatabaseReader({ user }, ctx.db, rules);
lee
lee5mo ago
GitHub
convex-helpers/packages/convex-helpers/server/rowLevelSecurity.ts a...
A collection of useful code to complement the official packages. - get-convex/convex-helpers
brianmmdev
brianmmdevOP5mo ago
That’s where I was able to deduce it from. Is there a way to NOT apply rules tho? Ideally u just want to inject the user object into the context so I can use it to secure queries and mutations individually
jamwt
jamwt5mo ago
plain old withUser (the first example) does that if you want to manually apply rules you don't need wrapDatabaseWriter/Reader
brianmmdev
brianmmdevOP5mo ago
Thanks again Jamie. This worked great!

Did you find this page helpful?