Home > OS >  How to check same user has second times login using redux react native with example
How to check same user has second times login using redux react native with example

Time:09-01

I need to navigation after a same user visits when logsIn to our app 2 times. Has anyone an opinion on how would be the best approach for this using redux react native with example because I am new in Redux.

here is my code,

export const userLogin = (data, navigation) => {
  return dispatch => {
    let headers = {
      'Content-Type': 'application/json',
    };
    axios
      .post(`${Url}api/auth/login`, data, {headers: headers})
      .then(resp => {
        let response = resp.data;
        let verified = resp.data.user.isVerified;
        dispatch(setCurrentUser(response.user));
        dispatch(setAuthToken(response.access_token));
        dispatch(setLoader(false));
        if (verified) {
          navigation.dispatch(
            CommonActions.reset({
              index: 0,
              routes: [{name: 'mainRoutes'}],
            }),
          );
        } else {
          navigation.navigate('confirmYourEmail', {email: data.email});
        }
      })
      .catch(error => {
        const err = error;
        if (err.response) {
          showMessage(err.response.data.message);
        }
        dispatch(setLoader(false));
      });
  };
};

CodePudding user response:

Can you elaborate what you are saying? And also try sharing the code, so that people can understand the issue better.

CodePudding user response:

you can set one flag in you user table as onboarded, based on that you can decide which screen to be shown and once they click skip or next-next-next change your onboarded state. using this approach if user uninstall the app, still you have data that user have been onboarded, but in redux you won't be able to keep data if user uninstall and then install. if you want to make user see onboarding screen every time they install the app, then you can use redux.

  • Related