AFUA
Convex Community10mo ago
4 replies
AFU

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  
  }
})


// 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)
  },
})


Thank you
Was this page helpful?