Skip to content

Commit aead5f7

Browse files
committed
Step 17.18: Create getFbProfile Meteor method
1 parent 81d8474 commit aead5f7

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

‎api/server/methods.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { MessageType, Profile } from './models';
44
import { check, Match } from 'meteor/check';
55
import { Users } from "./collections/users";
66
import { fcmService } from "./services/fcm";
7+
import { facebookService, FbProfile } from "./services/facebook";
78

89
const nonEmptyString = Match.Where((str) => {
910
check(str, String);
@@ -118,5 +119,17 @@ Meteor.methods({
118119
check(token, nonEmptyString);
119120

120121
Users.collection.update({_id: this.userId}, {$set: {"fcmToken": token}});
122+
},
123+
async getFbProfile(): Promise<FbProfile> {
124+
if (!this.userId) throw new Meteor.Error('unauthorized', 'User must be logged-in to call this method');
125+
126+
if (!Users.collection.findOne({'_id': this.userId}).services.facebook) {
127+
throw new Meteor.Error('unauthorized', 'User must be logged-in with Facebook to call this method');
128+
}
129+
130+
//TODO: handle error: token may be expired
131+
const accessToken = await facebookService.getAccessToken(this.userId);
132+
//TODO: handle error: user may have denied permissions
133+
return await facebookService.getProfile(accessToken);
121134
}
122135
});

0 commit comments

Comments
 (0)