Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clearAndNavigate(screen) {
- this.props.navigation.dispatch(
- NavigationActions.reset({
- index: 0,
- actions: [
- NavigationActions.navigate({ routeName: screen })
- ]
- })
- );
- }
- componentWillMount() {
- this.CheckUserLogin()
- }
- async CheckUserLogin() {
- let user = await AsyncStorage.getItem('dataLogin')
- if (user !== null) {
- console.log(user)
- this.clearAndNavigate('Home')
- } else {
- this.setState({
- isLoading: false
- })
- }
- }
- //for login\\\
- LoginUser = () =>{
- if (this.state.email == "") {
- ToastAndroid.show('Email can not be empty', ToastAndroid.SHORT)
- } else if (this.state.password == "") {
- ToastAndroid.show('Password can not be empty', ToastAndroid.SHORT)
- } else {
- this.setState({
- loading: false
- })
- axios({
- method: 'POST',
- url: 'http://192.168.214.2/Auth/user',
- data: {
- email : this.state.email,
- password : this.state.password
- },
- }).then(response => {
- if (response.data.status) {
- ToastAndroid.show('Welcome', ToastAndroid.SHORT)
- // this.storageAsyncStorage(response.data)
- // this.clearAndNavigate('Home')
- AsyncStorage.setItem('dataLogin', JSON.stringify(response.data))
- console.log(response.data);
- }else{
- ToastAndroid.show('Email Atau Password salah', ToastAndroid.SHORT)
- ToastAndroid.showWithGravityAndOffset('Please check your username and password',
- ToastAndroid.LONG, ToastAndroid.CENTER, 25, 50 );
- console.log(response.data);
- // ToastAndroid.show('sukses', ToastAndroid.SHORT)
- }
- }).catch(err => {
- this.setState({
- loading : false
- })
- })
- Keyboard.dismiss()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement