Skip to content

Commit 1b58035

Browse files
dotansimhadarkbasic
authored andcommitted
Step 7.29: Added restriction on new message method
1 parent 8d50ffb commit 1b58035

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

api/server/methods.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ Meteor.methods({
2222
});
2323
},
2424
addMessage(type: MessageType, chatId: string, content: string) {
25+
if (!this.userId) throw new Meteor.Error('unauthorized',
26+
'User must be logged-in to create a new chat');
27+
2528
check(type, Match.OneOf(String, [ MessageType.TEXT ]));
2629
check(chatId, nonEmptyString);
2730
check(content, nonEmptyString);
@@ -36,6 +39,7 @@ Meteor.methods({
3639
return {
3740
messageId: Messages.collection.insert({
3841
chatId: chatId,
42+
senderId: this.userId,
3943
content: content,
4044
createdAt: new Date(),
4145
type: type

0 commit comments

Comments
 (0)