timur.k

nubie
Hey everyone!

how to add axios package?

there is no option in custom packages to enter the npm url

"axios": {
Β  Β  Β  "version": "0.20.0",
Β  Β  Β  "resolved": "https://registry.npmjs.org/axios/-/axios-0.20.0.tgz",
Β  Β  Β  "integrity": "sha512-ANA4rr2BDcmmAQLOKft2fufrtuvlqR+cXNNinUmvfeSNCOF98PZL+7M/v1zIdGo7OLjEA9J2gXJL+j4zGsl0bA==",
Β  Β  Β  "requires": {
Β  Β  Β  Β  "follow-redirects": "^1.10.0"
Β  Β  Β  }
Β  Β  },Β 

using AxiosPostWithTimeout in custom code

Dont beat me too hard, I am a newbie, We use axios as api to authorise users. In order to use AxiosPostWithTimeout I firstΒ  added package in a custom section. My original code (outside of draftbit) looked like:


 const authContext = React.useMemo(
    () => ({
      signIn: (data: any) => { // : { username: string, password: string }
        let url = _consts.Url + "/mobile2/auth/createtoken";
        log("signIn start " + url);
        AsyncStorage.setItem(_consts.userNameForLog, data.username);
        AxiosPostWithTimeout(url, { username: data.username, password: data.password }, 2000)
          .then(async res => {
            log("got response " + url)
            AsyncStorage.setItem(_consts.userToken, res.data.token);
            dispatch({ type: 'SIGN_IN', token: res.data.token });
          })
          .catch(err => {
            if (err && err.response && err.response.status === 401)
              alert('wrong creentials')
            else
              alert('ERROR' + err)
          })
      },
      signOut: () => {
        AsyncStorage.removeItem(_consts.userToken);
        dispatch({ type: 'SIGN_OUT' });
      },

      openReq: (id: any) => apiGetReq(id),
    }),
    []
  );

  return (
    <ErrorBoundary>
      <AuthContext.Provider value={authContext}>
        <NavigationContainer ref={navigatorRef => { NavigationService.setTopLevelNavigator(navigatorRef); }}>
          <Stack.Navigator>
            {state.isLoading ? (
              // We haven't finished checking for the token yet
              <Stack.Screen name="Splash" component={SplashScreen} />
            ) : state.userToken == null ? (
              // No token found, user isn't signed in
              <Stack.Screen
                name="SignIn"
                component={SignInScreen}
                options={{
                  title: 'Sign in',
                  // When logging out, a pop animation feels intuitive
                  animationTypeForReplace: state.isSignout ? 'pop' : 'push',
                }}
              />
            ) : (

                  // User is signed in
                  (
                    <Stack.Screen name="Home" component={HomeScreen} />
                  )
                )
            }

          
            <Stack.Screen name="Req" component={ReqScreen} />

          </Stack.Navigator>
        </NavigationContainer>
      </AuthContext.Provider>
    </ErrorBoundary>
  );
}



I am wondering on which section of the custom menu should i post this code in order to properly connect my draftbit frontend to my database api?