Okay. This one was pretty nice. I asked copilot to build my endpoints and fix any errors that the originally generated code had and it all went pretty smoothly. Copilot even gave me curl
commands to check the endpoint was working as expected. And all before my gum lost its flavor!
I used inline copilot fix
command to resolve type errors and other warnings and didn't get any hallucinations.
Commit ada39425df6b6d5ba36ef910a56211e7e9b0d3be
I had an error because Copilot didn't include type definitions package, but pasting error into chat and voila. Pretty easy.
We're adding auth so we should probably read up on auth best practices a little bit directly, but this is a test project that isn't deployed anywhere yet so I'm not making that too big of a priority.
Commit 1a1642b6d0de9762fca6e59c5f42f52f3a8c7f61
Looks like we just need to apply @UseGuards(JwtAuthGuard)
above my protected routes and we'll get a 401
Let's do a little cleanup...
Commit 4981d49f475f2e4122b39a8c0455fbb9763c212a
Not too much to say other than that it looks like we were throwing plain text passwords all over willy-nilly. That should be cleaned up. At this point we could add tests here or move back to the front and start building these routes there.
Commit 42a94ee9d7f6fa02967713db409a2ddbd6a75c79
Okay, we have to create a bunch of new user role related stuff and we don't want to let someone through in a role argument and magically become a super user... aaaaaand now it looks like my validation pipe isn't working for auth.
After painstaking debugging... I needed to update my useGlobalPipes
in main.ts to
new ValidationPipe({
// forbidNonWhiteListed REQUIRES whitelist to be true
forbidNonWhitelisted: true,
transform: true,
whitelist: true,
}),
I had a bit of a gotcha. I left off whitelist: true
which meant there was no whitelist to forbid non whitelisted!
That should protect my validation from passing unwanted values on to the db.
After updating my DTOs and entities and routes and config we're left with:
Commit 84adba670b3711f5844a44c5668530aa75d93e61
What was I saying about moving to the front before I found a bunch of problems? Yeah, this is probably a good argument to add tests now so we don't run into MORE problems when we try to use this...