Spiced
Spiced13mo ago

Trying to create custom function

import { query } from "../_generated/server";
import { customQuery, customCtx } from "convex-helpers/server/customFunctions";

// Use `userQuery` instead of `query` to add this behavior.
const userQuery = customQuery(
query, // The base function we're extending
// Here we're using a `customCtx` helper because our modification
// only modifies the `ctx` argument to the function.
customCtx(async (ctx) => {
// Look up the logged in user
const identity = await ctx.auth.getUserIdentity();
if (!identity) throw new Error("Unauthorized");
// Pass in a user to use in evaluating rules,
// which validate data access at access / write time.
const db = wrapDatabaseReader({ identity }, ctx.db, rules);
// This new ctx will be applied to the function's.
// The user is a new field, the db replaces ctx.db
return { identity, db };
}),
);
import { query } from "../_generated/server";
import { customQuery, customCtx } from "convex-helpers/server/customFunctions";

// Use `userQuery` instead of `query` to add this behavior.
const userQuery = customQuery(
query, // The base function we're extending
// Here we're using a `customCtx` helper because our modification
// only modifies the `ctx` argument to the function.
customCtx(async (ctx) => {
// Look up the logged in user
const identity = await ctx.auth.getUserIdentity();
if (!identity) throw new Error("Unauthorized");
// Pass in a user to use in evaluating rules,
// which validate data access at access / write time.
const db = wrapDatabaseReader({ identity }, ctx.db, rules);
// This new ctx will be applied to the function's.
// The user is a new field, the db replaces ctx.db
return { identity, db };
}),
);
In this case the wrapDatabaseReader and rules are not being found. Any suggestions ?
1 Reply
Michal Srb
Michal Srb13mo ago
GitHub
convex-helpers/convex/customFunctionExample.ts at main · get-convex...
A collection of useful code to complement the official packages. - get-convex/convex-helpers

Did you find this page helpful?