2

I am working on a Xero integration and am having some issues setting up the XeroClient from the SDK. We are currently working in a React app written with Typescript.

Currently I am importing Xero SDK like this:

import { XeroClient } from 'xero-node';

And defining the client like this:

const xero = new XeroClient({
   clientId: client_id,
   clientSecret: client_secret,
   redirectUris: [redirectUri],
   scopes: scopes.split(' '),
});

Xero-node version: 4.0.6

React version: 16.12.0

But when compiling the app I get the following errors. Do you have any ideas as to what might be happening? Console Logs Browser Error

Might be related to this existing question.

Nathan
  • 90
  • 7

1 Answers1

1

Currently the xero-node project requires a backend to authenticate.. Is this a react SPA, or you are just setting up the API calls in the component?

Will OAuth 2.0 support desktop/mobile/single-page apps that can’t keep a client secret confidential?

At the moment, we require that your app can keep a client secret confidential. We are currently evaluating the PKCE extension to better support SPAs and mobile apps.

https://developer.xero.com/faq/oauth2/oauth-non-secret


Your Console error looks like its just the Unused vars expression.. Here is some context on what that is ( https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-vars.md )

Your Secondary browser error makes me think that you are using an older version of Node.. We need to add an .npmrc that forces a supported node version - are you using an older Node VSN?

SerKnight
  • 2,502
  • 1
  • 16
  • 18
  • 1
    Thanks Christopher! Yup that definitely a step in the right directly now. But not completely hundreds (possibly unrelated though) After moving the Xero code to the API, the error I am getting now is: ```error: Cannot set property 'Symbol(openid-client.custom.clock-tolerance)' of undefined``` From a brief look through the xero-node code, a possible source of the problem is [here](https://github.com/XeroAPI/xero-node/blob/28262113b6f811a41ec47efb23b4439a77145e79/src/xeroClient.ts#L36) but I am not sure - that looks like it should work as is – Nathan Jan 18 '20 at 14:27
  • 1
    Nvm I found the issue. There was a race condition on the `buildConsentUrl()` function which was depending on the `buildClient()` function to execution first. By taking this into account, the app now works with the SDK. Thanks for the assist! – Nathan Jan 21 '20 at 20:18
  • No worries - I actually fixed the clock tolerance error this week so that should be resolved w/out any hacks in the new versions of the package & the sample app (https://github.com/XeroAPI/xero-node-oauth2-app) – SerKnight Jan 22 '20 at 16:56