Skip to content

Commit e0e7214

Browse files
committed
Step 16.5: Create the saveFcmToken Meteor method
1 parent 8927c7d commit e0e7214

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

api/server/methods.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Chats } from './collections/chats';
22
import { Messages } from './collections/messages';
33
import { MessageType, Profile } from './models';
44
import { check, Match } from 'meteor/check';
5+
import { Users } from "./collections/users";
56

67
const nonEmptyString = Match.Where((str) => {
78
check(str, String);
@@ -94,5 +95,12 @@ Meteor.methods({
9495
},
9596
countMessages(): number {
9697
return Messages.collection.find().count();
98+
},
99+
saveFcmToken(token: string): void {
100+
if (!this.userId) throw new Meteor.Error('unauthorized', 'User must be logged-in to call this method');
101+
102+
check(token, nonEmptyString);
103+
104+
Users.collection.update({_id: this.userId}, {$set: {"fcmToken": token}});
97105
}
98106
});

0 commit comments

Comments
 (0)