Search code examples
javascriptparse-serveraccount-kit

Cannot read property "authenticate" of undefined - Parse Server with Account Kit


Issue Description

I am using Parse Server 3.0.0 and trying to get it to work with Facebook's Account Kit. I have followed the instructions in the docs and done the following:

  1. Configured facebookaccountkit inside auth passed to ParseServer()

var polaris = new ParseServer({
  databaseURI: 'mongodb://localhost:27017/polaris',
  cloud: __dirname + '/cloud/main.js',
  appId: 'polarisAppId',
  masterKey: 'polarisMasterKey',
  serverURL: 'http://' + ipAddress + ':1337/polaris',
  auth: {
    facebookaccountkit: {
      appIds: ["app_id_here"],
      appSecret: "app_secret_here"
    },
  }
});
  1. Getting Access Token inside my Android by going through phone verification.
  2. Calling _linkWith() in cloud code as:

let accountKitAuthData = {
    "id": accountKitId,
    "access_token": accessToken,
    "last_refresh": lastRefresh
}

let user = new Parse.User()
user._linkWith('facebookaccountkit', accountKitAuthData).then(function (user) {
    console.log("linkWith method finished ")
    console.log("user object type " + (typeof user))
});

However, after all this, I am getting the following error:

(node:21807) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'authenticate' of undefined`

My best guess is that the facebookaccountkit provider is not getting registered due to some reason but I may be wrong. Please help!

Expected Results

Linking of user with facebookaccountkit credentials

Actual Outcome

Error:

(node:21807) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'authenticate' of undefined`

Environment Setup

  • Server
    • parse-server version : 3.0.0
    • Operating System: Ubuntu
    • Hardware: -
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): Google Cloud Platform

Solution

  • Use this:

    let accountKitAuthData = {
        "id": accountKitId,
        "access_token": accessToken,
        "last_refresh": lastRefresh
    }
    
    let user = new Parse.User()
    user._linkWith('facebookaccountkit', { authData: accountKitAuthData }).then(function (user) {
        console.log("linkWith method finished ")
        console.log("user object type " + (typeof user))
    });