how to import prisma client on a client without compromising credentials
Hello, I would like to build an app using a monorepo. Since my backend will be using nestjs and my application react native. I would love to use prisma as an ORM to define my entities and reuse the types in both my nestjs and rn applications.
While it’s not a concern importing prisma client on my backend, I’m afraid that doing so on react native may lead to credentials leaks
Is there a way to get the types and the types only on my rn app?
7 Replies
Hi :vmathi: You an import Prisma types safely, those are only Typescript types. You just won't import the prisma client at any cost in your client or it will be compromised
I'm sorry but I didn't get what you said
I'm aware that I could import as "type" and that the imports would be remove after transpilation, but I'm not sure it will be the case if I use enum in my prisma schema because enums (if my memory is good, I could be wrong) are considered as object and I plan on using enum anyway.
I'm looking for a way to only expose my entities types to the RN app without having a lot of things to do once I change something in the schema
When you generate the Prisma client, you also generate types. Simply import those types:
I forgot how types are generated from the client 😅
I agree with that, but if it's an enum, it's a value and not a type and in this case, it won't work
But I might miss a point
My guess would be to recreate this enum based on the type
Or import it from prisma
In this case, I don't think I can use the enum, but I might be able to hardcode it like and still benefit type safety
If my enum looks something like:
I need to check but I think it might be ok, thanks for the idea
If anybody comes around here and have another take on this subject, then I would be glad to hear about it
Don't you have the
Status
enum available in exports from the client?