BogdanB
Convex Community3y ago
5 replies
Bogdan

Could not resolve "crypto"

I am trying to have a function that generates a code and returns it to the react client.


import crypto from 'crypto'
import { mutation } from "./_generated/server";

export const getSessionId = mutation({
    args: {},
    handler: async (ctx) => {
        let sessionId = generateCode()
        await ctx.db.insert("rooms", {sessionId: sessionId});
        return sessionId
    }
})

function generateCode() {
    return crypto.randomBytes(3).toString('hex').toUpperCase()
}

but then i get this error:

✘ [ERROR] Could not resolve "crypto"

    src/convex/room.ts:1:19:
      1 │ import crypto from 'crypto'


how would i resolve this? i also feel as though there is a gap in my understanding of how convex is supposed to work .
Was this page helpful?