如何使用React格子链接修复“ error_code:'INVALID_PUBLIC_TOKEN',[0] error_message:'找不到匹配的公共令牌'

时间:2019-04-28 20:16:03

标签: node.js reactjs express plaid

将格子链接转换为React组件时,出现以下错误: 错误代码:“ INVALID_PUBLIC_TOKEN”, [0] error_message:“找不到匹配的公共令牌”

我已经仔细检查了.env中的PLAID_CLIENT_ID,PLAID_SECRET和PLAID_PUBLIC_KEY,使其与PLAID中的对应项匹配。

 //HERE is the onSuccess function in my react component.

    axios.request({
      method: "POST",
      url: "/api/get_access_token",
      data: {
        public_token: token,
        account_id: metadata.account_id,
        accounts: metadata.accounts
      }
    }).then((res) => {
      console.log("Plaid post success", res.data)
      if (res.data.existingUser === true) {
        console.log('Plaid user = true');
      }
      else {

        history.replace('/home');
      }
    }).catch((err) => { console.log("userID post failed", err) });

    axios.request({
      method:"GET",
      url:"/api/updateUser"
    }).then(res => {

    }).catch(err => { console.log("updateUser Route error", err) })
  } ```

//And here is my server side code:
```app.post('/api/get_access_token', function (request, response, next) {

  PUBLIC_TOKEN = request.body.public_token;

  ACCOUNTS = request.body.accounts;

  ACCOUNT_ID = request.body.account_id;

  client.exchangePublicToken(PUBLIC_TOKEN, function (error, tokenResponse) {

    if (error != null) {
      prettyPrintResponse(error);
      return response.json({
        error: error,
      });
    }

    ACCESS_TOKEN = tokenResponse.access_token;
    console.log(ACCESS_TOKEN);
    ITEM_ID = tokenResponse.item_id;
    prettyPrintResponse(tokenResponse);

    return response.json(tokenResponse);
  });
});```

0 个答案:

没有答案