saito200
CCConvex Community
•Created by saito200 on 2/3/2024 in #support-community
Auth with chained actions and mutations?
I'm using a mutation that schedules an action. This action runs a bunch of actions one after the other. The first action runs a public mutation which has an authentication guard (a functiont that throws if the user is not auth). This function is throwing an error even if the user is logged in
10 replies
CCConvex Community
•Created by saito200 on 2/1/2024 in #support-community
Validator from schema, including internal fields?
I'm passing full DB records to one of my actions and I'm trying to build the validator
After some tinkering it looks like this:
I am exporting the validator from the
schema
similar as described here https://stack.convex.dev/types-cookbook
The fact that I have to add the _id manually feels a bit awkward to me, but I need the id to be used as a foreign key
Am I doing something weird? Is this simply ok? (the action uses some of the fields of the record to create a record for a different table)
What I started looking for originally was like a built-in validator that can be extracted from the schema or somewhere else, similar as you can get the DB record type with Doc<"myTable"> but the equivalent for validators, including internal fields2 replies
CCConvex Community
•Created by saito200 on 2/1/2024 in #support-community
How to use the result of a scheduled action?
My mutation schedules an action using
await ctx.scheduler.runAfter(0, ...)
The action returns a value that then is used by the mutation to write to the DB, or that's what I planned
Pseudocode:
But this is not how it works, right? Because the return value of a scheduled action is a promise that resolves to a Id<"_scheduled_functions">
So it looks like I have to schedule the action, and from the action itself run an internal mutation that writes the output of the action to the DB, i.e.:
1. Run public mutation
2. Schedule action
3. Action gets some external data
4. Action runs internal mutation to write to DB
Is that second way the "correct way"?8 replies