Skip to content

Commit

Permalink
check userId exists and userId is type uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielllllllllllllll committed Jun 29, 2024
1 parent 3807478 commit 304a98a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions services/api/controllers/friend/accept_invitation.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (

func (s Service) AcceptInvitation(ctx context.Context, req *monify.AcceptInvitationRequest) (*monify.FriendEmpty, error) {
logger := ctx.Value(lib.LoggerContextKey{}).(*zap.Logger)
userId := ctx.Value(lib.UserIdContextKey{}).(uuid.UUID)
if userId == uuid.Nil {
_, ok := ctx.Value(lib.UserIdContextKey{}).(uuid.UUID)
if !ok {
return nil, status.Error(codes.Unauthenticated, "Unauthorized.")
}

Expand Down
3 changes: 2 additions & 1 deletion services/api/controllers/friend/friend_invite.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ func (s Service) InviteFriend(ctx context.Context, req *monify.InviteFriendReque

logger := ctx.Value(lib.LoggerContextKey{}).(*zap.Logger)
userId := ctx.Value(lib.UserIdContextKey{}).(uuid.UUID)
if userId == uuid.Nil {
userId, ok := ctx.Value(lib.UserIdContextKey{}).(uuid.UUID)
if !ok {
return nil, status.Error(codes.Unauthenticated, "Unauthorized.")
}
receiver_nickId := req.GetReceiverNickId()
Expand Down
4 changes: 2 additions & 2 deletions services/api/controllers/friend/list_friend.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (

func (s Service) ListFriend(ctx context.Context, req *monify.FriendEmpty) (*monify.ListFriendResponse, error) {
logger := ctx.Value(lib.LoggerContextKey{}).(*zap.Logger)
userId := ctx.Value(lib.UserIdContextKey{})
if userId == nil {
userId, ok := ctx.Value(lib.UserIdContextKey{}).(uuid.UUID)
if !ok {
return nil, status.Error(codes.Unauthenticated, "Unauthorized.")
}
db := ctx.Value(lib.DatabaseContextKey{}).(*sql.DB)
Expand Down
5 changes: 3 additions & 2 deletions services/api/controllers/friend/list_friend_invitation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import (
"monify/lib"
monify "monify/protobuf/gen/go"

"github.com/google/uuid"
"go.uber.org/zap"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

func (s Service) ListFriendInvitation(ctx context.Context, req *monify.FriendEmpty) (*monify.ListFriendInvitationResponse, error) {
logger := ctx.Value(lib.LoggerContextKey{}).(*zap.Logger)
userId := ctx.Value(lib.UserIdContextKey{})
if userId == nil {
userId, ok := ctx.Value(lib.UserIdContextKey{}).(uuid.UUID)
if !ok {
return nil, status.Error(codes.Unauthenticated, "Unauthorized.")
}
db := ctx.Value(lib.DatabaseContextKey{}).(*sql.DB)
Expand Down
4 changes: 2 additions & 2 deletions services/api/controllers/friend/reject_invitation.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (

func (s Service) RejectInvitation(ctx context.Context, req *monify.RejectInvitationRequest) (*monify.FriendEmpty, error) {
logger := ctx.Value(lib.LoggerContextKey{}).(*zap.Logger)
userId := ctx.Value(lib.UserIdContextKey{}).(uuid.UUID)
if userId == uuid.Nil {
_, ok := ctx.Value(lib.UserIdContextKey{}).(uuid.UUID)
if !ok {
return nil, status.Error(codes.Unauthenticated, "Unauthorized.")
}
db := ctx.Value(lib.DatabaseContextKey{}).(*sql.DB)
Expand Down

0 comments on commit 304a98a

Please sign in to comment.