From 1f333485b6888d664c253c7d1002f51ae9898ff9 Mon Sep 17 00:00:00 2001 From: shani Date: Sun, 19 May 2024 16:31:17 +0700 Subject: [PATCH] fix stuff --- src/handler/auth_handler.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/handler/auth_handler.go b/src/handler/auth_handler.go index bc6f6ca..553cd71 100644 --- a/src/handler/auth_handler.go +++ b/src/handler/auth_handler.go @@ -30,6 +30,12 @@ func (h *AuthHandler) Register(c *gin.Context) { } // Validate request payload + if(request.Nip == 0) { + log.Println("Register bad request > invalid NIP") + c.JSON(400, gin.H{"status": "bad request", "message": "invalid NIP"}) + return + } + err = ValidateRegisterRequest(request.Nip, request.Name, request.Password) if err != nil { log.Println("Register bad request ", err) @@ -72,6 +78,12 @@ func (h *AuthHandler) Login(c *gin.Context) { c.JSON(400, gin.H{"status": "bad request", "message": err}) return } + + if(request.Nip == 0) { + log.Println("Register bad request > invalid NIP") + c.JSON(400, gin.H{"status": "bad request", "message": "invalid NIP"}) + return + } nStr := strconv.FormatInt(request.Nip, 10) if !strings.HasPrefix(nStr, "615") { @@ -105,7 +117,8 @@ func (h *AuthHandler) Login(c *gin.Context) { "data": gin.H{ "nip": userData.Nip, "name": userData.Name, - "accessToken": token, + "accessToken": token, + "userId": userData.Id, }, }) } @@ -158,7 +171,7 @@ func (h *AuthHandler) LoginNurse(c *gin.Context) { } // ValidateRegisterRequest validates the register user request payload -func ValidateRegisterRequest(nip int64, name, password string) error { +func ValidateRegisterRequest(nip int64, name string, password string) error { // Validate email format if !isValidNip(nip) { return errors.New("nip invalid")