From f73ea65a73de07214d2c8215b6a45cbed1856815 Mon Sep 17 00:00:00 2001 From: Ishan Arya Date: Mon, 29 Jul 2024 14:04:14 +0530 Subject: [PATCH] feat: use caller email if user email is missing in payload --- internal/api/v1beta1/user.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/api/v1beta1/user.go b/internal/api/v1beta1/user.go index cc4d71354..3453b146a 100644 --- a/internal/api/v1beta1/user.go +++ b/internal/api/v1beta1/user.go @@ -103,9 +103,14 @@ func (h Handler) CreateUser(ctx context.Context, request *shieldv1beta1.CreateUs return nil, grpcBadBodyError } + currentUserEmail, ok := user.GetEmailFromContext(ctx) + if !ok { + return nil, grpcUnauthenticated + } + email := strings.TrimSpace(request.GetBody().GetEmail()) if email == "" { - return nil, grpcBadBodyError + email = currentUserEmail } if !isValidEmail(email) { return nil, user.ErrInvalidEmail