The Bolg

Back to coding blogs 🧏🏾‍♂️

ok its time to finally create an e2e project

Problem: no discipline to daily read stuff. browse social med, too busy with work, too busy with shit idk. maybe skill issue. oh well what to do.

Solution: A site where you update what book you are reading, and it sends alerts via email or SMS if you have not logged daily read count!

i think a reasonable amount of time to complete this is until October 2024. I will update this entry with my progress, starting with Oauth. Im using google, because who doesnt have google oauth?

Browsed through the goat Eli Bendesrky’s excellent blogpost on Oauth: https://eli.thegreenplace.net/2024/sign-in-with-google-in-go/

The goal I had in mind, when user logs in, authenticates them and stores the session in DB, and also use the email as Primary Key when storing info about the user.

Luckily it was quite easy to implement; I preferred to use a third party library instead of handling auth myself, but also chose a library that was written by a cool guy that was also recommended by thegreenplace above, gologin https://pkg.go.dev/github.com/dghubble/gologin/v2

Handlers:

// i needed just three handlers for auth flow
	mux.Handle("/login/", google.StateHandler(googleCookieConfig, google.LoginHandler(conf, nil)))
	mux.Handle(callbackPath, google.StateHandler(googleCookieConfig, google.CallbackHandler(conf, http.HandlerFunc(googleCallbackHandler), nil)))
	mux.Handle("POST /logout", http.HandlerFunc(logoutHandler)

In the callback handler, I will be using the oauth information to store a user session, and also use the email as primary key to manage the user’s information.

Im using sessions library that is also provided by the dghubble guy, so if his auth lib goes down we all go down together man

The site looks like this now

loading...

And after login

loading...

Next, I will be adding smtp server to my VPS to support sending email to users, which is an important feature in this end to end project, stay tuned folks