0

I am using the ConnectyCube React Native SDK but not getting very far with it. When using its methods I am getting and error saying they are undefined like so: TypeError: Cannot read property 'createSession' of undefined. When I console.log ConnectyCube.createSession it logs:

ƒ createSession(params, callback) { this.auth.createSession(params, callback); }.

I have linked the package using react-native link connectycube-reactnative as I've read to do on other posts, but am still having the same problem. Anyone know what's wrong or how I could fix? Thanks in advance.

import ConnectyCube from 'connectycube-reactnative'
import config from './ConnectycubeConfig'

export default function App() { 

  console.log(ConnectyCube.createSession)

  var userCredentials = {login: 'xxxxxxxxx', password: 'xxxxxxxx'};

  ConnectyCube.createSession(userCredentials, (error, session) => {

  }); // 'TypeError: Cannot read property 'createSession' of undefined'
Mr. Robot
  • 1,334
  • 6
  • 27
  • 79
  • According to the documentation your import is wrong, it should be `import { ConnectyCube } from 'connectycube-reactnative'`. See the NPM package page. – nbokmans Aug 06 '19 at 14:16
  • Thanks, yes, but when I use that I get `Cannot read property 'apply' of undefined`. It also says you should use `const CB = new ConnectyCube()`, but then what? In the example apps they provide that work, they don't use either of those. – Mr. Robot Aug 06 '19 at 14:28

2 Answers2

1

Iam no expert react. What is see is there is common problem. According to your error, it says that 'connectyCude' is undefined. Try below code.

import {ConnectyCube} from 'connectycube-reactnative'
import config from './ConnectycubeConfig'

export default function App() { 
  var cCube = new ConnectyCube();
  console.log(cCube.createSession)

  var userCredentials = {login: 'xxxxxxxxx', password: 'xxxxxxxx'};

  cCube.createSession(userCredentials, (error, session) => {});
}
1

Please set it up and proceed with the session.

import ConnectyCube from 'connectycube-reactnative'
...
const cbConfig = [
    {
        appId: 218,
        authKey: 'p-cqm2aatn8ZPM3',
        authSecret: '3hmGuXN8AHZOgg6',
    },
    {
        debug: { mode: 1 },
    },
]
...
  componentWillMount() {
    ConnectyCube.init(...cbConfig)
    ConnectyCube.createSession((failSession, session) => {
      if (!failSession, session) {
       alert("you can get login")
      }
    })
   }
hong developer
  • 13,291
  • 4
  • 38
  • 68