A developer refactors an authentication microservice by integrating Prisma ORM. The process involves updating package dependencies, defining a Prisma schema, running database migrations, and replacing existing repository patterns with Prisma services across various modules including user controllers and JWT strategies.
Length 9:15
Captions English (Generated), Spanish (Auto-translated), French (Auto-translated), Korean (Auto-translated), Portuguese (Auto-translated), Vietnamese (Auto-translated) #prisma #refactoring #authentication #typescript #postgresql #nestjs #database #microservices #coding #software engineering
0:00 So now that we have a pattern in place to run with Prisma, 0:04 we're gonna refactor auth, which is gonna follow the same exact pattern. 0:08 Let's start off by going to the package.json and 0:12 adding the dependencies we know we're gonna need. 0:15 So I'll stop my container and CD into 0:19 the auth folder, which we know already has its own 0:22 package.json, so we can utilize this to install the 0:26 dependencies we're gonna need. We'll p npm install, 0:30 add Prisma Client again, and Prisma. 0:37 I'll also go ahead and now install the development 0:39 dependency, the dot 0:41 env CLI. 0:43 So now we have these dependencies, we can go back and start off by 0:47 creating our Prisma folder where we're gonna host our 0:50 schema and any migrations. 0:53 So let's create the 0:56 schema.prisma. 0:59 And now I'll go ahead and copy the existing schema.prisma we 1:03 have 1:03 for reservations. We can simply copy this and paste it into 1:07 auth. Since it's gonna be exactly the same, 1:10 we're now 1:11 outputting these types to our local auth node modules. 1:15 We're gonna be pulling off the database URL, and now we can change our 1:19 model to instead be the reservation. We know we have the user model. 1:24 So inside of the user, we have the ID. 1:27 Again, I want to declare as an integer that 1:30 will default auto-increment. So this will be the add ID. 1:35 Then we have the email of type string, 1:38 password string, 1:40 and finally roles, which is gonna be a string array. 1:44 So we can reference this as an array type. 1:47 So with our schema in place, let's go ahead and create a new 1:50 .env.local 1:52 where we know we're gonna provide the database URL. 1:55 So again, I'll copy this from our env.local in 1:58 reservations 1:59 now, 2:00 paste it in, and the only thing we have to swap out
The rest of the transcript is for members.
Sign in