приложение, над которым я работаю, столкнулось с проблемой входа пользователей, игнорируя лог авторизации c в части регистрации. Когда я консольный журнал, Redux обновляет статус так же, как я хотел, но внешний интерфейс не показывает страницу, как я хотел. Пожалуйста, помогите мне выяснить, почему приложение не работает так, как я намеревался. Технологией, которую я использовал, были Cognito, Redux и React native. Я поместил все коды, которые участвуют в этом процессе переключения, ниже.
Итак, файл моего приложения. js (logi c для переключения между внутренними приложениями). и страница входа / входа) похожа на
state = {
user: {},
isLoading: true
}
async componentDidMount() {
this.setState({ fontIsLoading: false })
try {
const user = await Auth.currentAuthenticatedUser()
this.setState({ user, isLoading: false })
} catch (err) {
this.setState({ isLoading: false })
}
}
changeState() {
console.log("inside change state is working")
this.setState({ loggedIn: true })
}
render() {
if (this.state.isLoading) return null
let loggedIn = false
if (this.props.auth.isAuthenticating === true && this.props.auth.firstTimeUser === false) {
loggedIn = true
}
if (loggedIn) {
return (
<InnerNav /> ///this is the StackNavigator create just for in app use
)
}
return (
<AuthNav /> ///this is the StackNavigator create just for sign in and sign up flow
)
}
}
мои Redux logi c равна
export const LOG_IN = 'LOG_IN'
export const LOG_IN_SUCCESS = 'LOG_IN_SUCCESS'
export const LOG_IN_FAILURE = 'LOG_IN_FAILURE'
export const LOG_OUT = 'LOG_OUT'
export const SIGN_UP = 'SIGN_UP'
export const SIGN_UP_SUCCESS = 'SIGN_UP_SUCCESS'
export const SIGN_UP_FAILURE = 'SIGN_UP_FAILURE'
export const SHOW_SIGN_IN_CONFIRMATION_MODAL = 'SHOW_SIGN_IN_CONFIRMATION_MODAL'
export const SHOW_SIGN_UP_CONFIRMATION_MODAL = 'SHOW_SIGN_UP_CONFIRMATION_MODAL'
export const CONFIRM_SIGNUP = 'CONFIRM_SIGNUP'
export const CONFIRM_SIGNUP_SUCCESS = 'CONFIRM_SIGNUP_SUCCESS'
export const CONFIRM_SIGNUP_FAILURE = 'CONFIRM_SIGNUP_FAILURE'
export const NO_LONGER_FIRST_TIME_USER = 'NO_LONGER_FIRST_TIME_USER'
export const CONFIRM_LOGIN = 'CONFIRM_LOGIN'
export const CONFIRM_LOGIN_SUCCESS = 'CONFIRM_LOGIN_SUCCESS'
export const CONFIRM_LOGIN_FAILURE = 'CONFIRM_LOGIN_FAILURE'
export const CONFIRM_RESET = 'CONFIRM_RESET'
const initialState = {
isAuthenticating: false,
user: {},
signUpError: false,
signInError: false,
confirmSignUpError: false,
confirmLoginError: false,
firstTimeUser: true,
signInErrorMessage: '',
signUpErrorMessage: '',
confirmSignUpErrorMessage: ''
}
export default (state = initialState, action) => {
switch (action.type) {
case CONFIRM_SIGNUP:
return {
...state,
isAuthenticating: false,
firstTimeUser: true
}
case CONFIRM_SIGNUP_SUCCESS:
return {
...state,
isAuthenticating: false,
firstTimeUser: true
}
case CONFIRM_SIGNUP_FAILURE:
return {
...state,
isAuthenticating: false,
confirmSignUpError: false,
confirmSignupErrorMessage: action.error.message,
firstTimeUser: true
}
case SIGN_UP:
return {
...state,
isAuthenticating: false,
firstTimeUser: true
}
case SIGN_UP_SUCCESS:
return {
...state,
isAuthenticating: false,
firstTimeUser: true
}
case NO_LONGER_FIRST_TIME_USER:
return {
...state,
isAuthenticating: true,
firstTimeUser: false
}
case SIGN_UP_FAILURE:
return {
...state,
isAuthenticating: false,
signUpError: true,
signUpErrorMessage: action.error.message,
firstTimeUser: true
}
case LOG_IN:
return {
...state,
isAuthenticating: false,
signInError: false,
firstTimeUser: false
}
case LOG_IN_SUCCESS:
return {
isAuthenticating: true,
user: action.user,
showSignInConfirmationModal: true,
firstTimeUser: false
}
case LOG_IN_FAILURE:
return {
...state,
isAuthenticating: false,
signInError: true,
signInErrorMessage: action.error.message,
firstTimeUser: false
}
}
}
И моя навигация
const AuthenticationNavigator = createStackNavigator({
Signin: {
screen: SignIn,
navigationOptions: {
header: null
}
},
SignUp: {
screen: SignUp,
navigationOptions: {
header: null
}
},
Agreement: {
screen: Agreement,
navigationOptions: {
header: null
}
},
ForgetPassword: {
screen: ForgetPassword,
navigationOptions: {
header: null
}
}
});
const AppNavigator = createSwitchNavigator({
FirstTimeSignUp: {
screen: FirstTimeSignUp,
navigationOptions: {
header: null
}
},
Auth: AuthenticationNavigator,
Intro: {
screen: Introduction,
navigationOptions: {
header: null
}
},
Settingup: {
screen: Settingup,
navigationOptions: {
header: null
}
}
});
export default createAppContainer(AppNavigator);
и
const InnerPageNavigator = createStackNavigator({
Community: {
screen: Community,
params: {},
navigationOptions: {
header: null
}
},
Emily: {
screen: Emily,
navigationOptions: {
title: 'Emily',
headerLeft: null,
headerTitleStyle: {
textAlign: 'center',
flexGrow: 1,
alignSelf: 'center',
fontFamily: 'Roboto-Bold',
}
}
},
Achievement: {
screen: Achievement,
navigationOptions: {
headerLeft: null,
title: 'Achievement',
headerTitleStyle: {
textAlign: 'center',
flexGrow: 1,
alignSelf: 'center',
fontFamily: 'Roboto-Bold',
}
}
},
AMA: {
screen: AMA,
navigationOptions: {
headerLeft: null,
title: 'AMA',
headerTitleStyle: {
textAlign: 'center',
flexGrow: 1,
alignSelf: 'center',
fontFamily: 'Roboto-Bold',
}
}
},
QuestionZoomin: {
screen: QuestionZoomin
},
Profile: {
screen: MyProfile
},
Assessment: {
screen: Assessment,
navigationOptions: {
title: 'Wellbeing Assessment'
}
},
MyContent:{
screen:MyContent,
navigationOptions: {
title: 'My content'
}
}
})
const InnerNavigator = createSwitchNavigator({
InnerPage: InnerPageNavigator
});
export default createAppContainer(InnerNavigator);