skip to Main Content

I am trying to build login functionality on react-native app , i am showing the api response on same screen either error or success in Text tags, this feature works perfectly on android emulator.when i install the release apk in my phone when i hit login the screen goes whitescreen.

const [loginUser, {isLoading, error, data, isSuccess, isError}] = useLoginUserMutation();

const OnSignInPressed = async () => {
    console.log("onsigninpressed")
    const formData = {email, password}
    res = await loginUser(formData);
    console.log("res", res.data.message)
    console.log("resss", res)
    if (res.data.message === 'User logged in successfully') {
        dispatch(login())
    }
}

return (
  <View style={styles.root}>
      <Text>Api Responses</Text>
      {isSuccess && <Text>success message: {data.message}</Text>}
      {error && <Text>error message: {error.data.message}</Text>}
      {error && <Text>error status: {error.status}</Text>}
      <Image source={Logo} style={styles.logo} resizeMode='contain'/>
      <Custominput placeholder="Email" value={email} setValue={setEmail}
                   autoCapitalize='none'/>
      <Custominput placeholder="Password" value={password} setValue={setPassword}
                   secureTextEntry={true}/>
      {/* <Custombutton text='Sign In' onPress={OnSignInPressed}/> */}
      <Button
        onPress={() => OnSignInPressed()}
        title="Sign in"
        color="#841584"
      />
      <Custombutton text='Forgot Password' type="TERTIARY" onPress=.
        {onForgotPressed}/>
      <Custombutton text="Don't have an account ? Create one" type="TERTIARY"
                    onPress={onSignupPressed}/>
  </View>

)

2

Answers


  1. A white screen means you are getting an error on the JS side. Looks like when you work on your emulator you catch this error and don’t stop the app, check your console.

    To add a global error handler you can use this solution https://github.com/a7ul/react-native-exception-handler

    Login or Signup to reply.
  2. instead of res=await loginUser(formData); it should be more like const res = await loginUser(formData);

    javascript variables must start with either const,let,var

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search