Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS: PrismaAdapter does not accept prisma client that has client extensions #6078

Closed
kennykingdev opened this issue Dec 15, 2022 · 10 comments
Closed
Assignees
Labels
adapters Changes related to the core code concerning database adapters good first issue Good issue to take for first time contributors help needed The maintainer needs help due to time constraint/missing knowledge prisma @auth/prisma-adapter stale Did not receive any activity for 60 days TypeScript Issues relating to TypeScript

Comments

@kennykingdev
Copy link

Question 馃挰

When using the new prisma client extensions that they introduced in 4.7.0, the type of the prisma client changes with whatever extensions you apply.

If you try to pass your extended prisma client into PrismaAdapter, TS complains about the types not matching what it expects.

For now I have both a standard prisma client and an extended client. I pass the standard client into PrismaAdapter and use the extended client where needed in callbacks and events.

I would prefer that PrismaAdapter accept an extended client so that I don't have import and use both clients in [...nextAuth].ts

How to reproduce 鈽曪笍

const prisma = new PrismaClient().$extends({
  name: 'fullName',
  result: {
    user: {
      fullName: {
        needs: { firstName: true, lastName: true },
        compute(user) {
          return `${user.firstName} ${user.lastName}`;
        },
      },
    },
  },
});

export const authOptions: NextAuthOptions = {
  adapter: PrismaAdapter(prisma),
  providers: [
    GoogleProvider({
      clientId: 'GOOGLE_CLIENT_ID',
      clientSecret: 'GOOGLE_CLIENT_SECRET',
    }),
  ],
};

Contributing 馃檶馃徑

Yes, I am willing to help answer this question in a PR

@kennykingdev kennykingdev added question Ask how to do something or how something works TypeScript Issues relating to TypeScript labels Dec 15, 2022
@balazsorban44
Copy link
Member

Technically you should not be using v4 yet:

"@prisma/client": ">=2.26.0 || >=3",

Happy to add support though, so is this just a TS issue? 馃

@balazsorban44 balazsorban44 added help needed The maintainer needs help due to time constraint/missing knowledge good first issue Good issue to take for first time contributors adapters Changes related to the core code concerning database adapters prisma @auth/prisma-adapter and removed question Ask how to do something or how something works labels Dec 16, 2022
@kennykingdev
Copy link
Author

Yes.

@stale
Copy link

stale bot commented Feb 17, 2023

It looks like this issue did not receive any activity for 60 days. It will be closed in 7 days if no further activity occurs. If you think your issue is still relevant, commenting will keep it open. Thanks!

@stale stale bot added the stale Did not receive any activity for 60 days label Feb 17, 2023
@tacomanator
Copy link

Temporary work around until supported:

import { PrismaClient } from "@prisma/client";
export const authOptions: NextAuthOptions = {
  adapter: PrismaAdapter(prisma as unknown as PrismaClient),
  ...
}

If necessary could replace PrismaClient with a type extracted from your extended client, as described in this article.

@stale stale bot removed the stale Did not receive any activity for 60 days label Feb 19, 2023
@stale
Copy link

stale bot commented Apr 25, 2023

It looks like this issue did not receive any activity for 60 days. It will be closed in 7 days if no further activity occurs. If you think your issue is still relevant, commenting will keep it open. Thanks!

@stale stale bot added the stale Did not receive any activity for 60 days label Apr 25, 2023
@stale
Copy link

stale bot commented May 8, 2023

To keep things tidy, we are closing this issue for now. If you think your issue is still relevant, leave a comment and we might reopen it. Thanks!

@stale stale bot closed this as completed May 8, 2023
@benjamin-guibert
Copy link

Any update on this?

@alvesvaren
Copy link

This is still an issue I think in the latest version of the adapter

@mamlzy
Copy link

mamlzy commented Jan 20, 2024

still facing an error using prisma.$extends. can you help why this is happen? @balazsorban44 , thank you.
image

here is my code:
image

all of this working fine, if i'm not using prisma extension.

@zhanlarr-ww
Copy link

Fixed by #9798 it seems, for others who arrive here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adapters Changes related to the core code concerning database adapters good first issue Good issue to take for first time contributors help needed The maintainer needs help due to time constraint/missing knowledge prisma @auth/prisma-adapter stale Did not receive any activity for 60 days TypeScript Issues relating to TypeScript
Projects
None yet
Development

No branches or pull requests

8 participants