Skip to content
This repository has been archived by the owner on Jan 7, 2019. It is now read-only.

Latest commit

 

History

History
64 lines (51 loc) · 1.92 KB

clean-logout.s.md

File metadata and controls

64 lines (51 loc) · 1.92 KB

[Standard] Implementing a clean logout

Checks

You should remove all persisted and in-memory user content after a logout. You should logout from every external services silently.

  • If my project uses react-apollo
  • If my project uses redux
    • there is a LOGOUT or RESET_CUSTOMER_DATA action that replaces the user reducers' states with the initial states
  • If my project uses React-Native AsyncStorage
  • Errors should be caught and handled

Good examples

// pseudo code
const logout = async () => {
  try {
    await fetch('ZENDESK_LOGOUT_URL', { method: 'GET' });
    await firebase.auth().signOut();
    await AsyncStorage.clear();
    ReduxStore.dispatch(resetCustomerData());
    apolloClient.resetStore();
    Navigation.navigate('login');
  } catch (e) {
    HandleErrorService.handleError(e);
    // eventually show an error or retry
  }
}

Bad examples

Example 1

Without cleaning the user data, you will have state and data inconsistencies with the new user.

// pseudo code
const logout = async () => {
  Navigation.navigate('login');
}

Example 2

Without the try catch, the app will crash if the user has no connection, or if another error happens.

// pseudo code
const logout = async () => {
    await fetch('ZENDESK_LOGOUT_URL', { method: 'GET' });
    await firebase.auth().signOut();
    await AsyncStorage.clear();
    ReduxStore.dispatch(resetCustomerData());
    apolloClient.resetStore();
    Navigation.navigate('login');
}