Unhandled Promise rejection: Typeerror: Undefined is not an Object (evaluating '_context.t0.data.error') at expo

Asked

Viewed 343 times

0

my expo is giving this error on my login page, can you help me? here is my code

 export default class Signin extends Component {

     state ={
         errorMessage: null
     }

here I use apisauce to post on my api with credentials

   signin = async() => {
       try{
         const response = await api.post('/auth/authenticate')({
             email:'[email protected]',
             password:'123'
         })
    

         const {user, token} = response.data
         await AsyncStorage.multiSet([
             ['@backend : token', token]
             ['@backend : user',JSON.stringify(user) ]
         ])

the expo says the error is here

       }catch(response){
         this.setState({errorMessage: response.data.error})
       }
    
   }

   render() {
      return (
       <View style={styles.Container}>
            { this.state.errorMessage && <Text>{ this.state.errorMessage }</Text> }
         <Button onPress={this.signin} title="Entrar"/>
       </View>
     );
   }
 }

here my services/api

 import { create } from 'apisauce'


 const api = create({
     baseURL: 'http://locahost:300'
 })

 api.addResponseTransform(response => {
     if (!response.ok) throw response;
     console.log(response)
 })

 export default api;
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.