Skip to content

Commit

Permalink
fix: set is_verified in db during signup
Browse files Browse the repository at this point in the history
  • Loading branch information
moonpatel committed Nov 12, 2024
1 parent b17b0f5 commit 0fa1e29
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/controllers/auth_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ func (ac *AuthController) VerifyOTP(c *fiber.Ctx) error {
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{"error": "OTP not valid"})
}

err = ac.authService.SetIsVerified(verifyOtpBody.Id)
if err != nil {
return err
}

sessionId, err := ac.sessionService.CreateSession(verifyOtpBody.Id)
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Failed to create session"})
Expand Down
4 changes: 4 additions & 0 deletions internal/repositories/user_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ func (r *UserRepository) GetUser(uuid string) (*models.User, error) {

return user, nil
}

func (r *UserRepository) UpdateUser(id string, updates *models.User) error {
return r.db.Model(&models.User{}).Where("id = ?", id).Updates(updates).Error
}
4 changes: 4 additions & 0 deletions internal/services/auth_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ func (as *AuthService) VerifyOTP(verifyOtpBody *validators.VerifyOTP) (bool, err
}
return true, nil
}

func (as *AuthService) SetIsVerified(id string) error {
return as.userRepo.UpdateUser(id, &models.User{IsVerified: true})
}

0 comments on commit 0fa1e29

Please sign in to comment.