From 10e80208d6ef5453ebd7b1b67af41dab4cf89f11 Mon Sep 17 00:00:00 2001 From: DAB0mB Date: Thu, 9 Feb 2017 00:03:40 -0200 Subject: [PATCH] Step 7.28: Added restriction on new message method --- server/methods.ts | 4 ++++ 1 file changed, 4 insertions(+) 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