AFU
AFU3w ago

How can I get return value from "use node" action inside mutation ?

How can I get return value from "use node" action inside mutation ? - I try thisctx.runAction but got error "runAction does not exist", - So I move to ctx.scheduler but can not get response from that // hashActions.ts
"use node"

import bcrypt from 'bcryptjs'
import { action } from './_generated/server'
import { v } from 'convex/values'

export const hashPassword = action({
args: { password: v.string() },
handler: (ctx, args) => {
const hashedPassword = bcrypt.hashSync(args.password, "$2a$10$eImiTXuWVxfM37uY4JANjQ")
console.log('hashedPassword:', hashedPassword)
return hashedPassword
}
})
"use node"

import bcrypt from 'bcryptjs'
import { action } from './_generated/server'
import { v } from 'convex/values'

export const hashPassword = action({
args: { password: v.string() },
handler: (ctx, args) => {
const hashedPassword = bcrypt.hashSync(args.password, "$2a$10$eImiTXuWVxfM37uY4JANjQ")
console.log('hashedPassword:', hashedPassword)
return hashedPassword
}
})
// userAuths.tsx
export const signUpEmail = mutation({
args: {
email: v.string(),
password: v.string(),
},
handler: async (ctx, args) => {
const passwordHash = await ctx.scheduler.runAfter(
0,
api.hashActions.hashPassword,
{ password: args.password },
)
/** SEEM THIS return scheduler id or something but not what I expect */
console.log('passwordHash:', passwordHash)
},
})
export const signUpEmail = mutation({
args: {
email: v.string(),
password: v.string(),
},
handler: async (ctx, args) => {
const passwordHash = await ctx.scheduler.runAfter(
0,
api.hashActions.hashPassword,
{ password: args.password },
)
/** SEEM THIS return scheduler id or something but not what I expect */
console.log('passwordHash:', passwordHash)
},
})
Thank you
3 Replies
Convex Bot
Convex Bot3w ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
erquhart
erquhart3w ago
“use node” isn’t actually important here - you can’t use runAction from a mutation, only from another action. You could use an action to hash the password and then use runMutation to insert the email and hashed password to the database. You could also start with a mutation that inserts the email and leaves the hashed password blank, and then schedule the node action to hash the password and runMutation to insert it. That may or may not be worth the effort depending on how you’re handling client state during creation.
AFU
AFUOP3w ago
I see, thank you for your info. I will hash then pass to mutation

Did you find this page helpful?