Reaact-нативный редукс-аутентификационный вопрос - PullRequest
0 голосов
/ 30 апреля 2020

У меня проблема с системой аутентификации, я использую избыточность для обработки состояний приложения, когда я нахожусь в режиме отладки, система аутентификации работает нормально, но когда я генерирую apk релиза, он не работает

вот мой код

Экран аутентификации

/* eslint-disable react-native/no-inline-styles */
/* eslint-disable prettier/prettier */
// eslint-disable-next-line react-native/no-inline-styles
import React, { useState } from 'react';
import {
    Image,
    Text,
    TextInput,
    View,
    TouchableOpacity,
    ActivityIndicator
} from 'react-native';
import back from '../../assets/images/loginBackground.png';
import logo from '../../assets/images/logoLogin.png';
import tick from '../../assets/images/tick.png';
import eye from '../../assets/images/eye.png';
import * as RootNavigation from '../services/RootNavigation.js';
import {
    authentificationAction,
    getShopsAction
} from '../actions'
import { connect } from 'react-redux'

class AuthentificationScreen extends React.Component {
    state = {
        email: 'salim@salim.salim',
        password: '1234567890',
        loading: false
    }
    constructor(props) {
        super(props);
    }


    render() {
        return (
            <View
                style={{
                    width: '100%',
                    height: '100%',
                }}
            >
                <Image
                    style={{
                        position: 'absolute',
                        width: 420,
                        height: '100%',
                    }}
                    source={back}
                />
                <View style={{
                    width: '100%',
                    height: '110%',
                    alignItems: 'center',
                    justifyContent: 'space-around',
                    padding: 25,
                }}>
                    <Image
                        style={{
                            width: 300,
                            resizeMode: 'contain',
                        }}
                        source={logo}
                    />
                    <View
                        style={{
                            width: '100%',
                            alignItems: 'center',
                        }}
                    >
                        <View
                            style={{
                                width: '100%',
                            }}
                        >
                            <Text
                                style={{
                                    color: 'white',
                                }}
                            > Email
                            </Text>
                            <View style={{
                                flexDirection: 'row',
                                justifyContent: 'space-between',
                                borderBottomWidth: 1,
                                borderBottomColor: 'white',
                                marginBottom: 20,
                            }}>
                                <TextInput
                                    style={{
                                        flex: 1,
                                        color: 'white',
                                    }}
                                    onChangeText={
                                        (text) => {
                                            this.setState({ email: text })
                                        }
                                    }
                                />
                                <Image
                                    source={tick}
                                    style={{
                                        width: 20,
                                        resizeMode: 'contain',
                                    }}
                                />
                            </View>
                            <Text
                                style={{
                                    color: 'white',
                                }}
                            >Password
                            </Text>
                            <View style={{
                                flexDirection: 'row',
                                justifyContent: 'space-between',
                                borderBottomWidth: 1,
                                borderBottomColor: 'white',
                            }}>
                                <TextInput
                                    style={{
                                        flex: 1,
                                        color: 'white',
                                    }}
                                    onChangeText={
                                        (text) => {
                                            this.setState({ password: text })
                                        }
                                    }
                                    secureTextEntry
                                />
                                <Image
                                    source={eye}
                                    style={{
                                        width: 20,
                                        resizeMode: 'contain',
                                    }}
                                />
                            </View>
                        </View>

                        <TouchableOpacity
                            style={{
                                justifyContent: 'center',
                                alignItems: 'center',
                                marginTop: 45,
                                backgroundColor: '#e9442f',
                                width: '100%',
                                height: 50,
                                borderRadius: 20,
                            }}
                            onPress={ 
                                () =>{
                                    this.props.authentificationAction({
                                        email: this.state.email,
                                        password: this.state.password
                                    })

                                    RootNavigation.navigate("MainScreen")

                                    if (this.state.email != null && this.state.password != null) {
                                        this.props.authentificationAction({
                                            email: this.state.email,
                                            password: this.state.password
                                        })


                                    } else {
                                        alert('Data not defined')
                                    }
                                }
                            }
                        >
                            {
                                this.state.loading == false

                                    ? <Text
                                        style={{
                                            color: 'white',
                                            fontSize: 15,
                                            fontFamily: 'Lato-Black',
                                        }}
                                    >
                                        Login
                                    </Text>

                                    : <ActivityIndicator size="large" color="#fff" />

                            }

                        </TouchableOpacity>
                    </View>


                </View>
            </View>
        );
    }
}

//export default  AuthentificationScreen
function mapDispatchToProps(dispatch) {
    return {
        authentificationAction: (data) => dispatch(authentificationAction(data)),
        getShopsAction: () => dispatch(getShopsAction()),
    }
}

function mapStateToProps(state) {
    return {
        result: state.authentification.user,
        pending: state.authentification.pending,
        success: state.authentification.success,
        error: state.authentification.error
    }
}
export default connect(
    mapStateToProps,
    mapDispatchToProps
)(
    AuthentificationScreen
)

После использования нажмите кнопку подключения, я проверяю тип пользователя здесь

/* eslint-disable react-native/no-inline-styles */
/* eslint-disable prettier/prettier */
// eslint-disable-next-line react-native/no-inline-styles
import React, { useState } from 'react';
import {
    Image,
    Text,
    TextInput,
    View,
    TouchableOpacity,
    ActivityIndicator
} from 'react-native';
import back from '../../assets/images/loginBackground.png';
import logo from '../../assets/images/logoLogin.png';
import tick from '../../assets/images/tick.png';
import eye from '../../assets/images/eye.png';
import * as RootNavigation from '../services/RootNavigation.js';
import MapScreen from './MapScreen'
import ProviderScreen from './Provider/ProviderScreen'
import {
    authentificationAction,
    getShopsAction
} from '../actions'
import { connect } from 'react-redux'
import PendingComponent from '../components/PendingComponent';

class MainScreen extends React.Component {

    constructor(props) {
        super(props);
    }

    renderPending(){
        return(
            <PendingComponent color={ true }/>
        )
    }

    renderClient(){
        return(
            <MapScreen/>
        )
    }

    renderProvider(){
        return(
            <ProviderScreen/>
        )
    }
    renderConsole(){
        console.log("this.props.pending")
        console.log(this.props.pending)
        console.log("this.props.success")
        console.log(this.props.success)
        console.log("=================")
        console.log("=================")

        console.log( this.props.result.data != undefined ? this.props.result.data.token : 'no data ')


        console.log("=================")
        console.log("=================")
        console.log("this.props.error")
        console.log(this.props.error)
    }

    redirectionMethod(){
        alert(this.props.success)
        alert(this.props.pending)
        alert(this.props.error)
        if (
            this.props.success == true && this.props.result.state != "problem"
        ) {
            if (this.props.result.data != undefined) {
                if (this.props.result.data.token == 'ROLE_PROVIDER') {
                    RootNavigation.navigate("ProviderRouter")
                    return ( <ProviderScreen/> )
                } else {
                    this.props.getShopsAction()
                    return ( <MapScreen/> )

                }
            }

        }else{
            RootNavigation.navigate("Authentification")
        }
    }
    render(){
        return(
            <View>
                {
                    this.props.success != true 

                    ? this.renderPending()

                    : this.redirectionMethod()
                }
            </View>
        )
    }
}

//export default  MainScreen
function mapDispatchToProps(dispatch) {
    return {
        authentificationAction: (data) => dispatch(authentificationAction(data)),
        getShopsAction: () => dispatch(getShopsAction()),
    }
}

function mapStateToProps(state) {
    return {
        result: state.authentification.user,
        pending: state.authentification.pending,
        success: state.authentification.success,
        error: state.authentification.error
    }
}
export default connect(
    mapStateToProps,
    mapDispatchToProps
)(
    MainScreen
)

спасибо за помогает.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...