I think this is the first entry about me restarting my PetTake project. Well, I've been working on it for a few days now. I only managed to scratch the surface of "Node in Action" book in a span of a week, and I'm planning on to continue it in the short future. Now is to finish the unfinished business at PetTake. I've targeted to finish only the big chunks of it, enough to demonstrate its features. I expect it to not have any bug on major features, while also expecting a lot of rough edges such as CSS and overall unrefined error handling. I believe those little details are actually the one that take the bigger chunk of development time. Maybe if I feel like it, I'll refine PetTake later when I get a bit more stable on my current situation.

The big chunks that are left to build are: User authentication, Pagination, and sending an Email. Since I intentionally postponed the user authentication at the earlier stage of development, I'm kind of have bitten the bullet here. I initially want to do a research on many different authentication methods such as Passport + Session, JWT as cookie, and JWT + refresh token. Well, there are a lot more authentication methods out there that I ought to learn. But I just don't have the time. I hope the good wind will blow over me so that I don't need to restraint myself so much from learning all these juicy stuff.

In the end, I chose the most familiar auth method, Passport + Session using Local Strategy (username and password). The classic one. I usually tailor made my local strategy using bcrypt, but I use third-party mongoose auth package called "passport-local-mongoose" for this one. This package is a convenient plugin for your auth system. Most of the important thing such as authentication strategy, session management, and error messages are provided from this package. Maybe the only dirty work I need to do is to handle the errors.

Handling errors from a fetch call hold me up a bit. I've said it many times before, handling errors in an application is an intricate work. Maybe even more intricate than building the "working" part of the app. I still don't have a good grasp on how to create a more universal yet specific way to handle errors. Universal in a way that the whole app can use this error handling pattern. And specific in a way that each component can express their own errors in their preferred way.

On the other hand, I also want to utilize more of the HTTP codes (200, 404, 500, etc.). Such as when the user failed when logging into the app due to incorrect username or password, I want the server to give 401 code along with custom message to the client. But Axios (a request package) throws an error when the response has HTTP code other than 1xx, 2xx, or 3xx. Code 4xx and 5xx are basically errors in HTTP request world.  I'm using a trycatch pattern and if Axios throws an error, it will enter the catch block. I haven't explored the detail yet, but I have yet to find a way to incorporate HTTP error codes and a custom message for client-side to use.

For now, I settled with a manual way of doing things, that is using a "success" indicator. Login and register are all working properly right now. There is a few bit more to do in regards of UI authentication routing, but that won't take long, I believe. The next big chunk will be pagination. That's it for today. Thank you for reading and I hope things go well for you.


This free site is ad-supported. Learn more