fmsouza / nubank-api

A high level API to connect to Nubank service and download your purchase records.
GNU General Public License v3.0
116 stars 19 forks source link

HTTPS Agent issue on ReactNative #16

Open Niltonsf opened 2 years ago

Niltonsf commented 2 years ago

I have implemented in the following way, but I get an error on the api call, the error is that `request('https'') was not defined. Error:

If you are sure the module exists, try these steps:
 1. Clear watchman watches: watchman watch-del-all
 2. Delete node_modules and run yarn install
 3. Reset Metro's cache: yarn start --reset-cache
 4. Remove the cache: rm -rf /tmp/metro-*
  50 | exports.Http = void 0;
  51 | var axios_1 = require("axios");
> 52 | var https_1 = require("https");
     |                        ^
  53 | var fs_1 = require("fs");
  54 | var constants_1 = require("../constants");
  55 | var Http = /** @class */ (function () {]
import React, { useEffect } from 'react';
import { Container, Text } from './styles';
import Animated from 'react-native-reanimated';
import { NubankApi } from "nubank-api"; 
import uuid from 'react-native-uuid';

export function Settings({ drawerAnimationStyle}: any){
    const CPF: string = "2";
    const PASSWORD: string = "2";
    const AUTH_CODE: string = String(uuid.v4());

      cont api = NubankApi();

    async function Nubank(): Promise<any> {
        try {
            await NubankApi.auth.authenticateWithQrCode(CPF, PASSWORD, AUTH_CODE);
            console.log("You are authenticated!");
            console.log(api.authState);             
            process.exit(0);
        } catch (e) {
            console.log(e);
        }   
     }

    return (
        <Animated.View 
            style={{
                flex: 1,
                ...drawerAnimationStyle
            }}
        >
            <Container>
                <Text>Comming soon!</Text>
            </Container>
        </Animated.View>
    );
}
fmsouza commented 2 years ago

@Niltonsf this dependency is native to Node.js, and looks like you are using in a ReactNative app. Ideally this would only be required in case you need to make the request using a HTTPS Agent. For now as a workaround, try to install this package and see if it works for you:

npm install https
Niltonsf commented 2 years ago

It didn't work unfortunately. The library doesn't seem to work with React Native.

fmsouza commented 2 years ago

I've managed to reproduce this error locally recently when trying to use the lib in a ReactNative app as well. This is indeed an issue, and so far the best path to fix it is not clear to me. Need more research.