-
-
Notifications
You must be signed in to change notification settings - Fork 30
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fields that are selected through include are returned as cyphertext #92
Comments
Could you paste the debug logs here (redacting any relevant values) please? |
Actually I don't think the include matters. I'm also getting it for regular selects.
|
Ah I see, you have to do special things with Next.js to prevent hot-reloading to stack up the middlewares, see #61 (comment). Let me know if that fixes it for you. |
I instantiate my prisma client like so, which is roughly the same as in that comment I think and it doesn't work: import { PrismaClient } from "@prisma/client/edge";
import { withAccelerate } from "@prisma/extension-accelerate";
import { fieldEncryptionExtension } from 'prisma-field-encryption'
const globalForPrisma = globalThis as unknown as { prisma: PrismaClient };
export const prisma =
globalForPrisma.prisma ||
new PrismaClient({
log:
process.env.NODE_ENV === "development"
? ["query", "error", "warn"]
: ["error"],
})
.$extends(withAccelerate())
.$extends(fieldEncryptionExtension());
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
export default prisma; |
I also have the same problem, with a similar setup (I tried accelerate too, but removed it for now). When I am on prisma Here is my debug output: Debug output
And my globally configured prisma on NextJs 14: prisma.tsimport { Prisma, PrismaClient } from './client';
import { fieldEncryptionExtension } from 'prisma-field-encryption';
import { loadEnvironment } from '@ss/environment-loader';
import { isProd } from '@ss/environment';
loadEnvironment();
declare global {
// eslint-disable-next-line no-var
var prisma: PrismaClient | undefined;
}
export const prisma =
global.prisma ||
new PrismaClient({
datasources: {
db: {
url: process.env.DATABASE_URL,
},
},
log: isProd() ? ['query', 'info', 'warn', 'error'] : [],
});
if (!global.prisma) {
prisma.$extends(fieldEncryptionExtension({ dmmf: Prisma.dmmf }));
}
if (!isProd()) {
global.prisma = prisma;
} On my case I am not doing this within an include although might be why I did a root resolver in this sample code /*
* This is a workaround, as I am not sure how type-graphql-prisma handles queries. Nested resolvers that
* need the pin found themselves with an encrypted value instead of an unencrypted one. This works around that,
* although not performant.
*/
@FieldResolver(() => String)
async pin(@Root() user: User, @Ctx() { prisma }: Context): Promise<string> {
const foundUser = await prisma.user.findUnique({ where: { id: user.id } });
return foundUser?.pin || user.pin;
} I also double checked that the encrypted pin is not double encrypted, it is the same as found within the database |
Another interesting thing here is that I tried using the deprecated // prisma.$extends(fieldEncryptionExtension({ dmmf: Prisma.dmmf }));
prisma.$use(fieldEncryptionMiddleware({ dmmf: Prisma.dmmf })) I noticed that the difference between the extension and the middleware is that the extension uses Maybe that is a separate issue though, not too sure. |
When doing a query which includes encrypted fields, rather than selecting them directly, the field will return encrypted.
Example of my prisma schema:
The text was updated successfully, but these errors were encountered: