Is "logInWith" broken on parse-server when using GraphQL?

Viewed 30

I'm running parse-server 4.5.0 with the GrahQL configured. When I try to login with Facebook I'm getting an error "This authentication method is unsupported". I did some digging into the internals of parse-server and it appears the authData is not getting read correctly. I edited GraphQL/loaders/usersMutations.js and put a console.log inside the logInWith function:

mutateAndGetPayload: async (args, context, mutationInfo) => {
  try {
    const {
      fields,
      authData
    } = args;
    const {
      config,
      auth,
      info
    } = context;
    console.log('## CJB 1, authData: ', authData);
    const parseFields = await (0, _mutation.transformTypes)('create', fields, {
      className: '_User',
      parseGraphQLSchema,
      req: {
        config,
        auth,
        info
      }
    });
    const {
      sessionToken,
      objectId
    } = await objectsMutations.createObject('_User', _objectSpread(_objectSpread({}, parseFields), {}, {
      authData
    }), config, auth, info);
    context.info.sessionToken = sessionToken;
    return {
      viewer: await (0, _usersQueries.getUserFromSessionToken)(context, mutationInfo, 'viewer.user.', objectId)
    };
  } catch (e) {
    parseGraphQLSchema.handleError(e);
  }
}

And what gets printed to the console is this:

## CJB 1, authData:  { facebook: { id: undefined, access_token: undefined } }

Here is what my request payload looks like:

{
  "operationName": "PerformLogIn",
  "query": "mutation PerformLogIn($email: String!, $userId: String!, $token: String!) {\n  logInWith(\n    input: {authData: {facebook: {id: $userId, access_token: $token}}, fields: {email: $email}}\n  ) {\n    viewer {\n      sessionToken\n      user {\n        email\n        id\n        username\n        __typename\n      }\n      __typename\n    }\n    __typename\n  }\n}\n",
  "variables": {
    "email": "user@email.com",
    "userId": "userId",
    "token": "tokenvalue"
  }
}

Any thoughts would be greatly appreciated.

To add more details, I tried passing this: input: {authData: {facebook: "foo"}}. And that prints out ## CJB 1, authData: { facebook: 'foo' }. So it seems like the GraphQL value is not being read correctly?

1 Answers

Holy cow...so the solution was to pass an entire object in the variables, not the individual strings. Here's what the final request looks like that worked:

{
  "operationName": "PerformLogIn",
  "query": "mutation PerformLogIn($email: String!, $authData: Object!) {\n  logInWith(\n    input: {authData: $authData, fields: {email: $email}}\n  ) {\n    viewer {\n      sessionToken\n      user {\n        email\n        id\n        username\n        __typename\n      }\n      __typename\n    }\n    __typename\n  }\n}\n",
  "variables": {
    "email": "user@email.com",
    "authData": {
      "facebook": {
        "id": "userId",
        "access_token": "tokenvalue"
      }
    }
  }
}
Related