I am trying to trigger a login with tKey in a React Native (bare) app. I followed along the instructions and the React example, but I am getting this error when I attempt to trigger a login: ReferenceError: Can't find variable: document
The stack trace indicates that the error originates from this line in CustomAuth, which judging by its use of the global document
variable, seems to assume that the code is running in the browser. But in a React Native mobile app, that is obviously not the case.
The right solution seems to be to use a different serviceProvider when instantiating the threshold key, since the TorusServiceProvider is built on top of CustomAuth and breaks when used in a mobile app rather than a browser. However, TorusServiceProvider seems like the only service provider that can actually interact with the Torus network-- ServiceProviderBase looks like it just has helpers for serialization and encryption.
So far I have tried creating a new subclass of ServiceProviderBase that uses customauth-react-native-sdk, but I’ve been unsuccessful so far. That SDK has a slightly different API than the CustomAuth web SDK, and I’m wondering if it is actually the right approach.
Could you provide an example, or at least high-level advice, for integrating with tKey in a react native application, given that TorusServiceProvider appears not to work outside a browser?
Here is my code:
const torusServiceProvider = new TorusServiceProvider({
customAuthArgs: {
baseUrl: `celo://wallet`, // tried several different URLs here
network: 'testnet',
},
})
const tKey = new ThresholdKey({
serviceProvider: torusServiceProvider,
})
await (tKey.serviceProvider as TorusServiceProvider).init({skipInit: true}) // without skipInit, hangs forever
try {
const loginResponse = await (tKey.serviceProvider as TorusServiceProvider).triggerLogin({
typeOfLogin: 'google',
verifier: 'google-oauth-alfajores',
clientId: '1067724576910-j7aqq89gfe5c30lnd9u8jkt7837fsprm.apps.googleusercontent.com',
})
Logger.info(TAG, `loginResponse: ${JSON.stringify(loginResponse)} `)
} catch (e) {
Logger.error(TAG, `Error triggering login: ${e} , stack: ${e.stack}`)
}
Please provide the following details too when asking for help in this category:
- SDK Version: 7.2.0
- Verifier Details:
- Verifier Name: google-oauth-alfajores