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
Heya. First actual real link: https://github.com/get-convex/convex-helpers/blob/main/convex/lib/withUser.ts
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
Wrap database helpers are here: https://github.com/get-convex/convex-helpers/blob/main/packages/convex-helpers/server/rowLevelSecurity.ts
GitHub
convex-helpers/packages/convex-helpers/server/rowLevelSecurity.ts a...
A collection of useful code to complement the official packages. - get-convex/convex-helpers
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.
Yes that looks right. You can see the types here https://github.com/get-convex/convex-helpers/blob/10cd8b3a2b26335d4a22906a4332ced71dac3ebc/packages/convex-helpers/server/rowLevelSecurity.ts#L21
GitHub
convex-helpers/packages/convex-helpers/server/rowLevelSecurity.ts a...
A collection of useful code to complement the official packages. - get-convex/convex-helpers
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
plain old
withUser
(the first example) does that if you want to manually apply rules
you don't need wrapDatabaseWriter/Reader
Thanks again Jamie. This worked great!