Skip to content

Commit

Permalink
Restrict access to other user conversations (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
harishmohanraj authored Nov 21, 2023
1 parent 1a4565f commit 7e13995
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions main.wasp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ entity User {=psl

externalAuthAssociations SocialLogin[]
chats Chat[]
conversations Conversation[]
psl=}
// relatedObject RelatedObject[] - add in line 86
entity SocialLogin {=psl
Expand Down Expand Up @@ -130,6 +131,8 @@ entity Conversation {=psl
updatedAt DateTime @updatedAt
chat Chat? @relation(fields: [chatId], references: [id])
chatId Int?
user User? @relation(fields: [userId], references: [id])
userId Int?
psl=}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE "Conversation" ADD COLUMN "userId" INTEGER;

-- AddForeignKey
ALTER TABLE "Conversation" ADD CONSTRAINT "Conversation_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
1 change: 1 addition & 0 deletions src/server/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export const createChat: CreateChat<void, Conversation> = async (_args, context)
},
],
chat: { connect: { id: chat.id } },
user: { connect: { id: context.user.id } },
},
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const getConversations: GetConversations<GetConversationPayload, Conversa
throw new HttpError(401);
}
return context.entities.Conversation.findFirstOrThrow({
where: { chatId: args.chatId },
where: { chatId: args.chatId, userId: context.user.id },
})
}

Expand Down

0 comments on commit 7e13995

Please sign in to comment.