Day 29 (week 6) — Authentication
I’m right in the middle of putting the finishing touches on my word-guessing-game. I had finished the basic functionality of this weekly project last weekend, but in the past few days we have been looking at authentication strategies using hashed passwords and also 3rd party authentication using passport with sites such as Twitter. So I’ve decided to try and add Twitter authentication to my word guessing game along with the ability to Tweet when you win a game.
This is definitely a bit of a stretch for me. But I think that’s a good thing.
First, I had to incorporate passport’s Twitter strategy into my app. This took a serious amount of reading in both the documentation online and Googling stuff on stack-exchange. Once I had successfully sent the OAuth2 request to Twitter, I could check and see if I got a token in response. I did, and that was my first little celebration.
Second, I had to figure out a way to use the token and sent a request to the Twitter API to post a status update to Twitter. More reading, more googling, more experimentation. Along the way, I figured a ton of stuff out and made good progress.
So right now, at 9:50pm, I have all the functionality working. I can do all of the things that I need to do. But I face another problem.
As part of my word-guessing-app, I wrote some client-side JS that listens for the user to press a key and take that as a guess. That JS does two things. First it sends a POST request to Express with the key that the user pressed. Second, it needs to refresh the page so that the updated information is shown to the user. This is where things get a bit tricky.
Since I didn’t anticipate doing all this Twitter auth stuff when I wrote the client-side JS, I inadvertently created a race condition. When the POST request is initiated, the code continues to run and sends another GET request to the server. So now I have two separate requests appearing on the server. The POST takes longer, as it requires more processing time. And so, by the time the POST request finishes processing, the GET request has already sent a response back to the client.
Long story short, what I really need to do is re-write this whole thing based on all my new understanding. I can continue to put band-aide fixes on this, but that only makes the code uglier.
I’m actually really quite pleased that I’m finding myself in this situation. The way I look at is this. When I started this project, I didn’t really understand how to get to the goal. In the process of working towards the goal, I learned a lot. There were also new things that caused me to change my goal and add new features to the app that I hadn’t originally planned for. I’m sitting here now, recognizing that there is really a much better way of doing things. It’s just unfortunate that I don’t have more time right now to re-write it.
The last time I felt this awesome about the work I was doing was way back in college working on my Electrical Engineering degree. It’s that feeling of doing something that you just can’t get enough of. You get so much energy from figuring out how stuff works and using that knowledge to solve problems.
I’m going to cut this post a bit short and see what I can finish tonight. I’m presenting this project to the group tomorrow and I want to make sure that everything is at least working as I expect. I’ll try and share more about this over the weekend.
