Skip to content

Commit 2248af4

Browse files
committed
feat: Validate login request to ensure either email or phone is provided
- Enhanced the `verifyLoginRequest` method in `AuthService` to check that at least one of the email or phone fields is populated in the `CompleteLoginRequest`. - Added error handling to return an `InvalidArgument` status if both fields are empty, improving request validation and user feedback. Signed-off-by: Christian Melgarejo <cmelgarejo@users.noreply.github.com>
1 parent f749753 commit 2248af4

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

modules/auth/internal/service/service.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,20 @@ func (s *AuthService) CompleteLogin(ctx context.Context, req *authv1.CompleteLog
165165
// This method handles business logic validation (magic code verification).
166166
// Note: The oneof requirement (email or phone) is handled by the validation interceptor.
167167
func (s *AuthService) verifyLoginRequest(ctx context.Context, req *authv1.CompleteLoginRequest) error {
168+
email := req.GetEmail()
169+
phone := req.GetPhone()
170+
171+
// Validate that at least one of email or phone is provided
172+
if email == "" && phone == "" {
173+
return status.Error(codes.InvalidArgument, "either email or phone must be provided")
174+
}
175+
168176
// With oneof, exactly one field will be set (validated by protovalidate)
169-
if req.GetEmail() != "" {
170-
return s.verifyMagicCodeByEmail(ctx, req.GetEmail(), req.Code)
177+
if email != "" {
178+
return s.verifyMagicCodeByEmail(ctx, email, req.Code)
171179
}
172180

173-
return s.verifyMagicCodeByPhone(ctx, req.GetPhone(), req.Code)
181+
return s.verifyMagicCodeByPhone(ctx, phone, req.Code)
174182
}
175183

176184
func (s *AuthService) verifyMagicCodeByEmail(ctx context.Context, email, code string) error {

0 commit comments

Comments
 (0)