diff --git a/server/methods.ts b/server/methods.ts index 43445c4..d8cf583 100644 --- a/server/methods.ts +++ b/server/methods.ts @@ -23,6 +23,9 @@ Meteor.methods({ }, addMessage(type: MessageType, chatId: string, content: string) { + if (!this.userId) throw new Meteor.Error('unauthorized', + 'User must be logged-in to create a new chat'); + check(type, Match.OneOf(String, [ MessageType.TEXT ])); check(chatId, nonEmptyString); check(content, nonEmptyString); @@ -37,6 +40,7 @@ Meteor.methods({ return { messageId: Messages.collection.insert({ chatId: chatId, + senderId: this.userId, content: content, createdAt: new Date(), type: type