@prisma/client as an Action dependency error

I am trying to use the package @prisma/client in an action to add a userId based on the incoming user’s email address. When I try to save my action after adding the dependency @prisma/client@latest I see the error:

" Error! The action failed to build. Double check your dependencies and try again."

Here is my action code:

exports.onExecutePostLogin = async (event, api) => {
  if (event.secrets.DATABASE_URL) {
    const PrismaClient = require('@prisma/client')
    const prisma = new PrismaClient()
    const author = prisma.author.findUnique({where: { email: event.user.email }})

    if (author) {
      api.user.setUserMetadata("authorId", author.id);
      api.idToken.setCustomClaim('authorId', author.id);
    } 
  }
};

Hi @KenEucker,

Welcome to the Auth0 Community!

I was able to deploy the Action by adding the entire Prisma package. Would that work for you here?

@dan.woda

I tried that, and was able to add a dependency “prisma” with @latest or @4.8.1, but, unfortunately, that didn’t work. Once deployed, while trying to log in, I get the error:

“Cannot find module ‘prisma/client’”

Screenshot 2023-01-09 at 4.35.30 PM

I have tried to include the dependency as “@prisma” “prisma” “prisma/client” and “@prisma/client” now and while the “prisma” dependency does seem to deploy, it doesn’t work in runtime. This is what I am following: Prisma Client



I don’t have any experience with Prisma, so please pardon my ignorance…How would this work if there is no schema for Prisma to read on installation? This would explain why adding the @prisma/client dependency is failing.

@dan.woda now you have me questioning what I am really doing in my life. :joy:

I don’t know if I was trying to do this because I saw it done elsewhere of if I just tried to tie Prisma into my Auth0 setup after discovering Actions. Maybe it was previously a Rule and now with Actions it is less possible to include a prisma schema? IDK.

I will look into a way to preload a prisma client with a schema from a URL or something. If I come up with something that works I will circle back here with my solution.

Cheers,

No problem! Let us know what you find.

Another option would be to build a lightweight API around your Prisma client that excepts requests from an Action and makes the necessary changes. You could probably do this is a serverless function or something of that nature.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.