Search code examples
iosgoogle-cloud-functionsplaid

why am I getting null when trying to get a link token from plaid?


I'm working in an iOS app with a Plaid integration to verify assets.

I cannot make the damn link token creation work...I get a 200 response but only NULL for the token

enter image description here

does anybody know what might be happening? enter image description here

this is the cloud function

const functions = require("firebase-functions");
//import { Configuration, PlaidApi, PlaidEnvironments } from "plaid";
const { Configuration, PlaidApi, PlaidEnvironments } = require("plaid");

exports.createPlaidLinkToken = functions.https.onCall(async (data, context) => {
  const customerId = context.auth.uid;

  //new instance version
  const configuration = new Configuration({
    basePath: PlaidEnvironments.development,
    baseOptions: {
      headers: {
        "PLAID-CLIENT-ID": functions.config().plaid.client_id,
        "PLAID-SECRET": functions.config().plaid.secret,
      },
    },
  });

  const plaidClient = new PlaidApi(configuration);

  //call the createLinkToken  METHOD of tge plaidClient instance!
  return plaidClient
    .linkTokenCreate({
      user: {
        client_user_id: customerId,
      },
      client_name: "Reny",
      products: ["auth"],
      country_codes: ["US"],
      language: "en",
    })
    .then((apiResponse) => {
      const linkToken = apiResponse.link_token;
      return linkToken;
    })
    .catch((err) => {
      console.log(err);
      throw new functions.https.HttpsError(
        "internal",
        " Unable to create plaid link token: " + err
      );
    });
});

cloud functions logs enter image description here


Solution

  • Just to provide closure for anybody who was curious, this issue was fixed by changing the lines...

    .then((apiResponse) => {
      const linkToken = apiResponse.link_token;
      return linkToken;
    })
    

    to...

    .then((apiResponse) => {
      const linkToken = apiResponse.data.link_token;
      return linkToken;
    })