diff --git a/gapi/rpc_signin_user.go b/gapi/rpc_signin_user.go deleted file mode 100644 index 8b8eb1e..0000000 --- a/gapi/rpc_signin_user.go +++ /dev/null @@ -1,58 +0,0 @@ -package gapi - -import ( - "context" - - "github.com/wpcodevo/golang-mongodb/pb" - "github.com/wpcodevo/golang-mongodb/utils" - "go.mongodb.org/mongo-driver/mongo" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" -) - -func (server *Server) SignInUser(ctx context.Context, req *pb.SignInUserInput) (*pb.SignInUserResponse, error) { - user, err := server.userService.FindUserByEmail(req.GetEmail()) - if err != nil { - if err == mongo.ErrNoDocuments { - - return nil, status.Errorf(codes.InvalidArgument, "Invalid email or password") - - } - - return nil, status.Errorf(codes.Internal, err.Error()) - - } - - if !user.Verified { - - return nil, status.Errorf(codes.PermissionDenied, "You are not verified, please verify your email to login") - - } - - if err := utils.VerifyPassword(user.Password, req.GetPassword()); err != nil { - - return nil, status.Errorf(codes.InvalidArgument, "Invalid email or Password") - - } - - // Generate Tokens - access_token, err := utils.CreateToken(server.config.AccessTokenExpiresIn, user.ID, server.config.AccessTokenPrivateKey) - if err != nil { - - return nil, status.Errorf(codes.PermissionDenied, err.Error()) - - } - - refresh_token, err := utils.CreateToken(server.config.RefreshTokenExpiresIn, user.ID, server.config.RefreshTokenPrivateKey) - if err != nil { - return nil, status.Errorf(codes.PermissionDenied, err.Error()) - } - - res := &pb.SignInUserResponse{ - Status: "success", - AccessToken: access_token, - RefreshToken: refresh_token, - } - - return res, nil -} diff --git a/pb/auth_service.pb.go b/pb/auth_service.pb.go index 76ccb80..09b8756 100644 --- a/pb/auth_service.pb.go +++ b/pb/auth_service.pb.go @@ -10,6 +10,7 @@ import ( protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" + sync "sync" ) const ( @@ -19,49 +20,103 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) +type VerifyEmailRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + VerificationCode string `protobuf:"bytes,1,opt,name=verificationCode,proto3" json:"verificationCode,omitempty"` +} + +func (x *VerifyEmailRequest) Reset() { + *x = VerifyEmailRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_auth_service_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *VerifyEmailRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*VerifyEmailRequest) ProtoMessage() {} + +func (x *VerifyEmailRequest) ProtoReflect() protoreflect.Message { + mi := &file_auth_service_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use VerifyEmailRequest.ProtoReflect.Descriptor instead. +func (*VerifyEmailRequest) Descriptor() ([]byte, []int) { + return file_auth_service_proto_rawDescGZIP(), []int{0} +} + +func (x *VerifyEmailRequest) GetVerificationCode() string { + if x != nil { + return x.VerificationCode + } + return "" +} + var File_auth_service_proto protoreflect.FileDescriptor var file_auth_service_proto_rawDesc = []byte{ 0x0a, 0x12, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x02, 0x70, 0x62, 0x1a, 0x15, 0x72, 0x70, 0x63, 0x5f, 0x73, 0x69, - 0x67, 0x6e, 0x69, 0x6e, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, - 0x15, 0x72, 0x70, 0x63, 0x5f, 0x73, 0x69, 0x67, 0x6e, 0x75, 0x70, 0x5f, 0x75, 0x73, 0x65, 0x72, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x15, 0x72, 0x70, 0x63, 0x5f, 0x76, 0x65, 0x72, 0x69, - 0x66, 0x79, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0a, 0x75, - 0x73, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x32, 0xc2, 0x01, 0x0a, 0x0b, 0x41, 0x75, - 0x74, 0x68, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x38, 0x0a, 0x0a, 0x53, 0x69, 0x67, - 0x6e, 0x55, 0x70, 0x55, 0x73, 0x65, 0x72, 0x12, 0x13, 0x2e, 0x70, 0x62, 0x2e, 0x53, 0x69, 0x67, - 0x6e, 0x55, 0x70, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x1a, 0x13, 0x2e, 0x70, - 0x62, 0x2e, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x69, 0x63, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x22, 0x00, 0x12, 0x3b, 0x0a, 0x0a, 0x53, 0x69, 0x67, 0x6e, 0x49, 0x6e, 0x55, 0x73, 0x65, - 0x72, 0x12, 0x13, 0x2e, 0x70, 0x62, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x49, 0x6e, 0x55, 0x73, 0x65, - 0x72, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x1a, 0x16, 0x2e, 0x70, 0x62, 0x2e, 0x53, 0x69, 0x67, 0x6e, - 0x49, 0x6e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, - 0x12, 0x3c, 0x0a, 0x0b, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x12, - 0x16, 0x2e, 0x70, 0x62, 0x2e, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x45, 0x6d, 0x61, 0x69, 0x6c, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x70, 0x62, 0x2e, 0x47, 0x65, 0x6e, - 0x65, 0x72, 0x69, 0x63, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x27, - 0x5a, 0x25, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x77, 0x70, 0x63, - 0x6f, 0x64, 0x65, 0x76, 0x6f, 0x2f, 0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x2d, 0x6d, 0x6f, 0x6e, - 0x67, 0x6f, 0x64, 0x62, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x67, 0x6e, 0x75, 0x70, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, + 0x0a, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x40, 0x0a, 0x12, 0x56, + 0x65, 0x72, 0x69, 0x66, 0x79, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x2a, 0x0a, 0x10, 0x76, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x76, 0x65, 0x72, + 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x64, 0x65, 0x32, 0x85, 0x01, + 0x0a, 0x0b, 0x41, 0x75, 0x74, 0x68, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x38, 0x0a, + 0x0a, 0x53, 0x69, 0x67, 0x6e, 0x55, 0x70, 0x55, 0x73, 0x65, 0x72, 0x12, 0x13, 0x2e, 0x70, 0x62, + 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x55, 0x70, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x70, 0x75, 0x74, + 0x1a, 0x13, 0x2e, 0x70, 0x62, 0x2e, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x69, 0x63, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3c, 0x0a, 0x0b, 0x56, 0x65, 0x72, 0x69, 0x66, + 0x79, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x16, 0x2e, 0x70, 0x62, 0x2e, 0x56, 0x65, 0x72, 0x69, + 0x66, 0x79, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, + 0x2e, 0x70, 0x62, 0x2e, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x69, 0x63, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x27, 0x5a, 0x25, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, + 0x63, 0x6f, 0x6d, 0x2f, 0x77, 0x70, 0x63, 0x6f, 0x64, 0x65, 0x76, 0x6f, 0x2f, 0x67, 0x6f, 0x6c, + 0x61, 0x6e, 0x67, 0x2d, 0x6d, 0x6f, 0x6e, 0x67, 0x6f, 0x64, 0x62, 0x2f, 0x70, 0x62, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } +var ( + file_auth_service_proto_rawDescOnce sync.Once + file_auth_service_proto_rawDescData = file_auth_service_proto_rawDesc +) + +func file_auth_service_proto_rawDescGZIP() []byte { + file_auth_service_proto_rawDescOnce.Do(func() { + file_auth_service_proto_rawDescData = protoimpl.X.CompressGZIP(file_auth_service_proto_rawDescData) + }) + return file_auth_service_proto_rawDescData +} + +var file_auth_service_proto_msgTypes = make([]protoimpl.MessageInfo, 1) var file_auth_service_proto_goTypes = []interface{}{ - (*SignUpUserInput)(nil), // 0: pb.SignUpUserInput - (*SignInUserInput)(nil), // 1: pb.SignInUserInput - (*VerifyEmailRequest)(nil), // 2: pb.VerifyEmailRequest - (*GenericResponse)(nil), // 3: pb.GenericResponse - (*SignInUserResponse)(nil), // 4: pb.SignInUserResponse + (*VerifyEmailRequest)(nil), // 0: pb.VerifyEmailRequest + (*SignUpUserInput)(nil), // 1: pb.SignUpUserInput + (*GenericResponse)(nil), // 2: pb.GenericResponse } var file_auth_service_proto_depIdxs = []int32{ - 0, // 0: pb.AuthService.SignUpUser:input_type -> pb.SignUpUserInput - 1, // 1: pb.AuthService.SignInUser:input_type -> pb.SignInUserInput - 2, // 2: pb.AuthService.VerifyEmail:input_type -> pb.VerifyEmailRequest - 3, // 3: pb.AuthService.SignUpUser:output_type -> pb.GenericResponse - 4, // 4: pb.AuthService.SignInUser:output_type -> pb.SignInUserResponse - 3, // 5: pb.AuthService.VerifyEmail:output_type -> pb.GenericResponse - 3, // [3:6] is the sub-list for method output_type - 0, // [0:3] is the sub-list for method input_type + 1, // 0: pb.AuthService.SignUpUser:input_type -> pb.SignUpUserInput + 0, // 1: pb.AuthService.VerifyEmail:input_type -> pb.VerifyEmailRequest + 2, // 2: pb.AuthService.SignUpUser:output_type -> pb.GenericResponse + 2, // 3: pb.AuthService.VerifyEmail:output_type -> pb.GenericResponse + 2, // [2:4] is the sub-list for method output_type + 0, // [0:2] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name @@ -72,22 +127,35 @@ func file_auth_service_proto_init() { if File_auth_service_proto != nil { return } - file_rpc_signin_user_proto_init() file_rpc_signup_user_proto_init() - file_rpc_verify_user_proto_init() file_user_proto_init() + if !protoimpl.UnsafeEnabled { + file_auth_service_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*VerifyEmailRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_auth_service_proto_rawDesc, NumEnums: 0, - NumMessages: 0, + NumMessages: 1, NumExtensions: 0, NumServices: 1, }, GoTypes: file_auth_service_proto_goTypes, DependencyIndexes: file_auth_service_proto_depIdxs, + MessageInfos: file_auth_service_proto_msgTypes, }.Build() File_auth_service_proto = out.File file_auth_service_proto_rawDesc = nil diff --git a/pb/auth_service_grpc.pb.go b/pb/auth_service_grpc.pb.go index 32facb3..e27f374 100644 --- a/pb/auth_service_grpc.pb.go +++ b/pb/auth_service_grpc.pb.go @@ -23,7 +23,6 @@ const _ = grpc.SupportPackageIsVersion7 // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type AuthServiceClient interface { SignUpUser(ctx context.Context, in *SignUpUserInput, opts ...grpc.CallOption) (*GenericResponse, error) - SignInUser(ctx context.Context, in *SignInUserInput, opts ...grpc.CallOption) (*SignInUserResponse, error) VerifyEmail(ctx context.Context, in *VerifyEmailRequest, opts ...grpc.CallOption) (*GenericResponse, error) } @@ -44,15 +43,6 @@ func (c *authServiceClient) SignUpUser(ctx context.Context, in *SignUpUserInput, return out, nil } -func (c *authServiceClient) SignInUser(ctx context.Context, in *SignInUserInput, opts ...grpc.CallOption) (*SignInUserResponse, error) { - out := new(SignInUserResponse) - err := c.cc.Invoke(ctx, "/pb.AuthService/SignInUser", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - func (c *authServiceClient) VerifyEmail(ctx context.Context, in *VerifyEmailRequest, opts ...grpc.CallOption) (*GenericResponse, error) { out := new(GenericResponse) err := c.cc.Invoke(ctx, "/pb.AuthService/VerifyEmail", in, out, opts...) @@ -67,7 +57,6 @@ func (c *authServiceClient) VerifyEmail(ctx context.Context, in *VerifyEmailRequ // for forward compatibility type AuthServiceServer interface { SignUpUser(context.Context, *SignUpUserInput) (*GenericResponse, error) - SignInUser(context.Context, *SignInUserInput) (*SignInUserResponse, error) VerifyEmail(context.Context, *VerifyEmailRequest) (*GenericResponse, error) mustEmbedUnimplementedAuthServiceServer() } @@ -79,9 +68,6 @@ type UnimplementedAuthServiceServer struct { func (UnimplementedAuthServiceServer) SignUpUser(context.Context, *SignUpUserInput) (*GenericResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method SignUpUser not implemented") } -func (UnimplementedAuthServiceServer) SignInUser(context.Context, *SignInUserInput) (*SignInUserResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method SignInUser not implemented") -} func (UnimplementedAuthServiceServer) VerifyEmail(context.Context, *VerifyEmailRequest) (*GenericResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method VerifyEmail not implemented") } @@ -116,24 +102,6 @@ func _AuthService_SignUpUser_Handler(srv interface{}, ctx context.Context, dec f return interceptor(ctx, in, info, handler) } -func _AuthService_SignInUser_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(SignInUserInput) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServiceServer).SignInUser(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/pb.AuthService/SignInUser", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServiceServer).SignInUser(ctx, req.(*SignInUserInput)) - } - return interceptor(ctx, in, info, handler) -} - func _AuthService_VerifyEmail_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(VerifyEmailRequest) if err := dec(in); err != nil { @@ -163,10 +131,6 @@ var AuthService_ServiceDesc = grpc.ServiceDesc{ MethodName: "SignUpUser", Handler: _AuthService_SignUpUser_Handler, }, - { - MethodName: "SignInUser", - Handler: _AuthService_SignInUser_Handler, - }, { MethodName: "VerifyEmail", Handler: _AuthService_VerifyEmail_Handler, diff --git a/pb/rpc_signin_user.pb.go b/pb/rpc_signin_user.pb.go deleted file mode 100644 index 7c14645..0000000 --- a/pb/rpc_signin_user.pb.go +++ /dev/null @@ -1,237 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.28.0 -// protoc v3.20.1 -// source: rpc_signin_user.proto - -package pb - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type SignInUserInput struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Email string `protobuf:"bytes,1,opt,name=email,proto3" json:"email,omitempty"` - Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` -} - -func (x *SignInUserInput) Reset() { - *x = SignInUserInput{} - if protoimpl.UnsafeEnabled { - mi := &file_rpc_signin_user_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *SignInUserInput) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*SignInUserInput) ProtoMessage() {} - -func (x *SignInUserInput) ProtoReflect() protoreflect.Message { - mi := &file_rpc_signin_user_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use SignInUserInput.ProtoReflect.Descriptor instead. -func (*SignInUserInput) Descriptor() ([]byte, []int) { - return file_rpc_signin_user_proto_rawDescGZIP(), []int{0} -} - -func (x *SignInUserInput) GetEmail() string { - if x != nil { - return x.Email - } - return "" -} - -func (x *SignInUserInput) GetPassword() string { - if x != nil { - return x.Password - } - return "" -} - -type SignInUserResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Status string `protobuf:"bytes,1,opt,name=status,proto3" json:"status,omitempty"` - AccessToken string `protobuf:"bytes,2,opt,name=access_token,json=accessToken,proto3" json:"access_token,omitempty"` - RefreshToken string `protobuf:"bytes,3,opt,name=refresh_token,json=refreshToken,proto3" json:"refresh_token,omitempty"` -} - -func (x *SignInUserResponse) Reset() { - *x = SignInUserResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_rpc_signin_user_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *SignInUserResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*SignInUserResponse) ProtoMessage() {} - -func (x *SignInUserResponse) ProtoReflect() protoreflect.Message { - mi := &file_rpc_signin_user_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use SignInUserResponse.ProtoReflect.Descriptor instead. -func (*SignInUserResponse) Descriptor() ([]byte, []int) { - return file_rpc_signin_user_proto_rawDescGZIP(), []int{1} -} - -func (x *SignInUserResponse) GetStatus() string { - if x != nil { - return x.Status - } - return "" -} - -func (x *SignInUserResponse) GetAccessToken() string { - if x != nil { - return x.AccessToken - } - return "" -} - -func (x *SignInUserResponse) GetRefreshToken() string { - if x != nil { - return x.RefreshToken - } - return "" -} - -var File_rpc_signin_user_proto protoreflect.FileDescriptor - -var file_rpc_signin_user_proto_rawDesc = []byte{ - 0x0a, 0x15, 0x72, 0x70, 0x63, 0x5f, 0x73, 0x69, 0x67, 0x6e, 0x69, 0x6e, 0x5f, 0x75, 0x73, 0x65, - 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x02, 0x70, 0x62, 0x22, 0x43, 0x0a, 0x0f, 0x53, - 0x69, 0x67, 0x6e, 0x49, 0x6e, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x12, 0x14, - 0x0a, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, - 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, - 0x22, 0x74, 0x0a, 0x12, 0x53, 0x69, 0x67, 0x6e, 0x49, 0x6e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x21, - 0x0a, 0x0c, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, - 0x6e, 0x12, 0x23, 0x0a, 0x0d, 0x72, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x5f, 0x74, 0x6f, 0x6b, - 0x65, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x72, 0x65, 0x66, 0x72, 0x65, 0x73, - 0x68, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x42, 0x27, 0x5a, 0x25, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, - 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x77, 0x70, 0x63, 0x6f, 0x64, 0x65, 0x76, 0x6f, 0x2f, 0x67, 0x6f, - 0x6c, 0x61, 0x6e, 0x67, 0x2d, 0x6d, 0x6f, 0x6e, 0x67, 0x6f, 0x64, 0x62, 0x2f, 0x70, 0x62, 0x62, - 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_rpc_signin_user_proto_rawDescOnce sync.Once - file_rpc_signin_user_proto_rawDescData = file_rpc_signin_user_proto_rawDesc -) - -func file_rpc_signin_user_proto_rawDescGZIP() []byte { - file_rpc_signin_user_proto_rawDescOnce.Do(func() { - file_rpc_signin_user_proto_rawDescData = protoimpl.X.CompressGZIP(file_rpc_signin_user_proto_rawDescData) - }) - return file_rpc_signin_user_proto_rawDescData -} - -var file_rpc_signin_user_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_rpc_signin_user_proto_goTypes = []interface{}{ - (*SignInUserInput)(nil), // 0: pb.SignInUserInput - (*SignInUserResponse)(nil), // 1: pb.SignInUserResponse -} -var file_rpc_signin_user_proto_depIdxs = []int32{ - 0, // [0:0] is the sub-list for method output_type - 0, // [0:0] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_rpc_signin_user_proto_init() } -func file_rpc_signin_user_proto_init() { - if File_rpc_signin_user_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_rpc_signin_user_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*SignInUserInput); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_rpc_signin_user_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*SignInUserResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_rpc_signin_user_proto_rawDesc, - NumEnums: 0, - NumMessages: 2, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_rpc_signin_user_proto_goTypes, - DependencyIndexes: file_rpc_signin_user_proto_depIdxs, - MessageInfos: file_rpc_signin_user_proto_msgTypes, - }.Build() - File_rpc_signin_user_proto = out.File - file_rpc_signin_user_proto_rawDesc = nil - file_rpc_signin_user_proto_goTypes = nil - file_rpc_signin_user_proto_depIdxs = nil -} diff --git a/pb/rpc_verify_user.pb.go b/pb/rpc_verify_user.pb.go deleted file mode 100644 index 7ed27a5..0000000 --- a/pb/rpc_verify_user.pb.go +++ /dev/null @@ -1,145 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.28.0 -// protoc v3.20.1 -// source: rpc_verify_user.proto - -package pb - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type VerifyEmailRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - VerificationCode string `protobuf:"bytes,1,opt,name=verificationCode,proto3" json:"verificationCode,omitempty"` -} - -func (x *VerifyEmailRequest) Reset() { - *x = VerifyEmailRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_rpc_verify_user_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *VerifyEmailRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*VerifyEmailRequest) ProtoMessage() {} - -func (x *VerifyEmailRequest) ProtoReflect() protoreflect.Message { - mi := &file_rpc_verify_user_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use VerifyEmailRequest.ProtoReflect.Descriptor instead. -func (*VerifyEmailRequest) Descriptor() ([]byte, []int) { - return file_rpc_verify_user_proto_rawDescGZIP(), []int{0} -} - -func (x *VerifyEmailRequest) GetVerificationCode() string { - if x != nil { - return x.VerificationCode - } - return "" -} - -var File_rpc_verify_user_proto protoreflect.FileDescriptor - -var file_rpc_verify_user_proto_rawDesc = []byte{ - 0x0a, 0x15, 0x72, 0x70, 0x63, 0x5f, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x5f, 0x75, 0x73, 0x65, - 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x02, 0x70, 0x62, 0x22, 0x40, 0x0a, 0x12, 0x56, - 0x65, 0x72, 0x69, 0x66, 0x79, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x12, 0x2a, 0x0a, 0x10, 0x76, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x76, 0x65, 0x72, - 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x64, 0x65, 0x42, 0x27, 0x5a, - 0x25, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x77, 0x70, 0x63, 0x6f, - 0x64, 0x65, 0x76, 0x6f, 0x2f, 0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x2d, 0x6d, 0x6f, 0x6e, 0x67, - 0x6f, 0x64, 0x62, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_rpc_verify_user_proto_rawDescOnce sync.Once - file_rpc_verify_user_proto_rawDescData = file_rpc_verify_user_proto_rawDesc -) - -func file_rpc_verify_user_proto_rawDescGZIP() []byte { - file_rpc_verify_user_proto_rawDescOnce.Do(func() { - file_rpc_verify_user_proto_rawDescData = protoimpl.X.CompressGZIP(file_rpc_verify_user_proto_rawDescData) - }) - return file_rpc_verify_user_proto_rawDescData -} - -var file_rpc_verify_user_proto_msgTypes = make([]protoimpl.MessageInfo, 1) -var file_rpc_verify_user_proto_goTypes = []interface{}{ - (*VerifyEmailRequest)(nil), // 0: pb.VerifyEmailRequest -} -var file_rpc_verify_user_proto_depIdxs = []int32{ - 0, // [0:0] is the sub-list for method output_type - 0, // [0:0] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_rpc_verify_user_proto_init() } -func file_rpc_verify_user_proto_init() { - if File_rpc_verify_user_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_rpc_verify_user_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*VerifyEmailRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_rpc_verify_user_proto_rawDesc, - NumEnums: 0, - NumMessages: 1, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_rpc_verify_user_proto_goTypes, - DependencyIndexes: file_rpc_verify_user_proto_depIdxs, - MessageInfos: file_rpc_verify_user_proto_msgTypes, - }.Build() - File_rpc_verify_user_proto = out.File - file_rpc_verify_user_proto_rawDesc = nil - file_rpc_verify_user_proto_goTypes = nil - file_rpc_verify_user_proto_depIdxs = nil -} diff --git a/proto-gen.sh b/proto-gen.sh new file mode 100644 index 0000000..1140d54 --- /dev/null +++ b/proto-gen.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +rm -rf pb/*.go +protoc --proto_path=proto --go_out=pb --go_opt=paths=source_relative \ + --go-grpc_out=pb --go-grpc_opt=paths=source_relative \ + proto/*.proto \ No newline at end of file diff --git a/proto/auth_service.proto b/proto/auth_service.proto index 8afdc3f..9890448 100644 --- a/proto/auth_service.proto +++ b/proto/auth_service.proto @@ -2,7 +2,6 @@ syntax = "proto3"; package pb; -import "rpc_signin_user.proto"; import "rpc_signup_user.proto"; import "user.proto"; @@ -10,7 +9,6 @@ option go_package = "github.com/wpcodevo/golang-mongodb/pb"; service AuthService { rpc SignUpUser(SignUpUserInput) returns (GenericResponse) {} - rpc SignInUser(SignInUserInput) returns (SignInUserResponse) {} rpc VerifyEmail(VerifyEmailRequest) returns (GenericResponse) {} } diff --git a/proto/rpc_signin_user.proto b/proto/rpc_signin_user.proto deleted file mode 100644 index f9b2621..0000000 --- a/proto/rpc_signin_user.proto +++ /dev/null @@ -1,16 +0,0 @@ -syntax = "proto3"; - -package pb; - -option go_package = "github.com/wpcodevo/golang-mongodb/pb"; - -message SignInUserInput { - string email = 1; - string password = 2; -} - -message SignInUserResponse { - string status = 1; - string access_token = 2; - string refresh_token = 3; -} \ No newline at end of file diff --git a/readMe.md b/readMe.md index ab77422..9b4b76a 100644 --- a/readMe.md +++ b/readMe.md @@ -1,4 +1,27 @@ -# API with Golang + MongoDB + Redis + Gin Gonic +# Build Golang gRPC Server and Client: SignUp User & Verify Email + +In this article, you'll learn how to create a gRPC server to register a user and verify their email address using Golang, MongoDB-Go-driver, Gomail, and Docker-compose. + +![Build Golang gRPC Server and Client: SignUp User & Verify Email](https://codevoweb.com/wp-content/uploads/2022/05/Build-Golang-gRPC-Server-and-Client-SignUp-User-Verify-Email.webp) + +## Topics Covered + +- gRPC Project setup in Golang +- Create the gRPC Request and Response Messages + - Define the gRPC User messages + - Define the gRPC Request and Response Message to SignUp User +- Create the gRPC Service Methods +- Generate the gRPC client and server interfaces +- Start the gRPC Server +- Test the gRPC API Server with Golang Evans +- Create the gRPC API Controllers + - Register User gRPC Controller + - Verify User gRPC Controller +- Create the gRPC Client to Register a User + +Read the entire article here: [https://codevoweb.com/golang-grpc-server-and-client-signup-user-verify-email](https://codevoweb.com/golang-grpc-server-and-client-signup-user-verify-email) + +Articles in this series: ### 1. API with Golang + MongoDB + Redis + Gin Gonic: Project Setup @@ -15,3 +38,19 @@ ### 4. API with Golang, Gin Gonic & MongoDB: Forget/Reset Password [API with Golang, Gin Gonic & MongoDB: Forget/Reset Password](https://codevoweb.com/api-golang-gin-gonic-mongodb-forget-reset-password) + +### 5. Build Golang gRPC Server and Client: SignUp User & Verify Email + +[Build Golang gRPC Server and Client: SignUp User & Verify Email](https://codevoweb.com/golang-grpc-server-and-client-signup-user-verify-email) + +### 6. Build Golang gRPC Server and Client: Access & Refresh Tokens + +[Build Golang gRPC Server and Client: Access & Refresh Tokens](https://codevoweb.com/golang-grpc-server-and-client-access-refresh-tokens) + +### 7. Build CRUD RESTful API Server with Golang, Gin, and MongoDB + +[Build CRUD RESTful API Server with Golang, Gin, and MongoDB](https://codevoweb.com/crud-restful-api-server-with-golang-and-mongodb) + +### 8. Build CRUD gRPC Server API & Client with Golang and MongoDB + +[Build CRUD gRPC Server API & Client with Golang and MongoDB](https://codevoweb.com/crud-grpc-server-api-client-with-golang-and-mongodb)