Permalink
Browse files

Step 17.18: Create getFbProfile Meteor method

  • Loading branch information...
darkbasic committed Jun 11, 2017
1 parent 27e007f commit bc48978d3ee6685b38955994fbb30a53cb5c764a
Showing with 13 additions and 0 deletions.
  1. +13 −0 api/server/methods.ts
View
@@ -4,6 +4,7 @@ import { MessageType, Profile } from './models';
import { check, Match } from 'meteor/check';
import { Users } from "./collections/users";
import { fcmService } from "./services/fcm";
import { facebookService, FbProfile } from "./services/facebook";
const nonEmptyString = Match.Where((str) => {
check(str, String);
@@ -118,5 +119,17 @@ Meteor.methods({
check(token, nonEmptyString);
Users.collection.update({_id: this.userId}, {$set: {"fcmToken": token}});
},
async getFbProfile(): Promise<FbProfile> {
if (!this.userId) throw new Meteor.Error('unauthorized', 'User must be logged-in to call this method');
if (!Users.collection.findOne({'_id': this.userId}).services.facebook) {
throw new Meteor.Error('unauthorized', 'User must be logged-in with Facebook to call this method');
}
//TODO: handle error: token may be expired
const accessToken = await facebookService.getAccessToken(this.userId);
//TODO: handle error: user may have denied permissions
return await facebookService.getProfile(accessToken);
}
});

0 comments on commit bc48978

Please sign in to comment.