User Authentication In E-Auc
In this blog we'll explore how we'll be implementing the user authentication in our application (e-auction).
Recently i have been using few application that have passwordless authentication and i sort of like that. I dont have to remember password for different applications. what they do is either they'll send a magic link on the email or an otp on phone number, since i believe most of our users would be using mobile phone we should send the otp in phone number and since I'll have to spend money to send text msg a better alternative would be sending the whatsapp message.
So we'll be setting up few extra services in this blog. that include.
Making a notification service, Rabbit MQ or kafka.
SMTP client to send email.
Whatsapp to send text message.
Redis server to store data in cache.
First lets start with creating user and sending them email without redis and notification service. So we'll create a CreateUser function in handler and in Service.
// cmd/routes.go
package main
import (
"fmt"
"net/http"
)
func (h *ChiHandler) CreateUser(w http.ResponseWriter, r *http.Request) {
// TODO: Create a new user from the request body and return 201 status code.
// Check the request body for required fields and validate them.
var createUserRequest CreateUserRequest
err := json.NewDecoder(r.Body).Decode(&createUserRequest)
if err != nil {
http.Error(w, "Invalid request body", http.StatusBadRequest)
return
}
err = createUserRequest.Validate()
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
fmt.Fprintln(w, "UnImplemented: Create User")
}
// service/user/user.go
NOTE: This blog is in implementation state. I am update this as i write code.