Backendless Support
 
Answered

backendless.UserService.login() user is logged in but no user object is returned

I am using the javascript sdk in a react-native app. In debug mode, everything is fine but in release mode, I can see in the panel that the user is successfully logged in but no user object is returned to me so the view never get updated.

Any help or advice is appreciated, thanks.

Here is my code:

  1. import {_ERR, _LOGIN} from "./types";

    import Backendless from "backendless";

    import {AsyncStorage} from "react-native";

    export const LoginUserAction = ({email, password, navigation}) => {

    return (dispatch) => {

    Backendless.UserService.login(email, password, true)

    .then(user => {

    console.dir(user);

    const userData = {

    token: Backendless.LocalCache.get('user-token'),

    id: Backendless.LocalCache.get('current-user-id'),

    ownerId: user.ownerId

    };

    dispatch({type: _LOGIN, payload: user.toString()});

    AsyncStorage.setItem('user', JSON.stringify(userData),(res)=>{

    console.log(res);

    navigation.navigate('drawerStack');

    }).catch(error =>{

    console.log(error);

    dispatch({type: _ERR, payload: error.message});

    });

    }).catch(error => {

    console.dir(error);

    dispatch({type: _ERR, payload: error.message});

    });

    }

    };

Best Answer
photo

For anyone that might come up with the same issue, I also tried the Backendless template but more problems came up due to old version of react native. At the end I used the Rest API (and not the JS SDK) and used fetch API to get data and the problem is solved now.

Leave a Comment

Comments (7)

photo
1

Hello,

Please be more specific, what do you mean by "no user object is returned"? Have you inspected what the "user" variable contains in 'then' after .login() call?

photo
1

Yes, I have. In debug mode, the user object is returned in 'then'. But in release mode 'then' part never runs. I can see in the panel that the user is successfully logged in but here in my app no data, no 'then' part, nothing! It only happens in release mode and I'm pretty sure the code is fine. I think something happens when I run 'gradlew assembleRelease'.

photo
1

Hi MZ B

1) Are your sure that this line works as correctly

  1. dispatch({ type: _LOGIN, payload: user.toString() });

I think user.toString() will return "[object Object]"

2) In ReactNative docs https://facebook.github.io/react-native/docs/asyncstorage.html#setitem I see that AsyncStorage.setItem returns a Promise if callback is not passed, so could you take a look on this:

  1. AsyncStorage.setItem('user', JSON.stringify(userData))
  2. .then(res => {
  3. console.log(res);
  4. navigation.navigate('drawerStack');
  5. })
  6. .catch(error => {
  7. console.log(error);
  8. dispatch({ type: _ERR, payload: error.message });
  9. });

photo
1

Apart from the `user.toString() ` ,which I added to my code to see if i see anything even `[object Object]` in my released app, the code works fine just as is in debug mode. If it was wrong, It wouldn't be working in debug mode. I only have this problem in release mode. No data actually returns from Backendless to be dispatched in my app. I have been struggling with this issue for more than 2 weeks now and believe me I have tried every possible solution I could think of.

photo
1

ok, could you please create a simple project with this problem and send it to support@backendless.com

and we will try to reproduce the problem

you can generate it via Console

ee76935c7ac9b4a8b140312a91704758

thanks,

photo
1

Thank you Vladimir. I downloaded the project template and realized that it's using react native 0.42 . My project dependencies are as follows:"dependencies": {

"backendless": "^4.3.0",

"react": "^16.0.0",

"react-native": "^0.51.0",

"react-navigation": "^1.0.0-beta.15",

"react-redux": "^5.0.6",

"redux": "^3.7.2",

"redux-thunk": "^2.2.0"

},

"devDependencies": {},

"jest": {

"preset": "react-native"

}

Let me try again with Backendless template and see if I bump into problem again.

Thank you again for your time and patience.

photo
1

For anyone that might come up with the same issue, I also tried the Backendless template but more problems came up due to old version of react native. At the end I used the Rest API (and not the JS SDK) and used fetch API to get data and the problem is solved now.