How do I REconfigure Meteor's accounts-facebook, or where is Meteor's Facebook configuration?

后端 未结 6 1563
灰色年华
灰色年华 2021-01-30 14:59

Meteor\'s accounts-facebook package was very easy to set up. To input the Facebook app ID and secret token, I loaded my meteor web app in a browser, and clicked on

6条回答
  •  后悔当初
    2021-01-30 15:55

    [NOTE: for Meteor >= 1.2.2]

    The official Meteor documentation here explains how to do it.

    Add the service-configuration package (otherwise you can't use ServiceConfiguration):

    $ meteor add service-configuration
    

    Then you can put this in Meteor.startup:

    Meteor.startup(function () {
    
      // Set Facebook app configurations
      ServiceConfiguration.configurations.upsert({ 
        service: "facebook" 
      }, {
        $set: {
          appId: 'YOUR_APP_ID',
          secret: 'YOUR_APP_SECRET'
        }
      });
    
      return;
    });
    

    Externalize Facebook configurations in settings.json

    Perhaps the final solution is to put Facebook app's configurations in a setting file

    /settings.json
    

    Like this:

    {
      "facebook" : {
        "appId": "APP_ID",
        "secret": "APP_SECRET"
      }
    }
    

    Then you have to start your Meteor application with

    $ meteor --settings settings.json
    

    in order to load the settings file.

    Finally you can load Facebook configurations inside Meteor.startup from the settings file:

    Meteor.startup(function () {
    
      // Load and set Facebook app configurations
      var facebookConfig = Meteor.settings.facebook;
      ServiceConfiguration.configurations.upsert({ 
        service: "facebook" 
      }, {
        $set: {
          appId: facebookConfig.appId,
          secret: facebookConfig.secret
        }
      });
    
      return;
    });
    

提交回复
热议问题