> For the complete documentation index, see [llms.txt](https://bamtech.gitbook.io/dev-standards/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bamtech.gitbook.io/dev-standards/react-native/features/clean-logout.s.md).

# clean-logout.s

## Owner: [Louis Lagrange](https://github.com/Minishlink)

## 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`
  * the cache is cleared with [client.resetStore](https://www.apollographql.com/docs/react/advanced/caching.html#reset-store)
* 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`
  * the cache is cleared with [AsyncStorage.clear](https://facebook.github.io/react-native/docs/asyncstorage.html#clear), or [AsyncStorage.multiRemove](https://facebook.github.io/react-native/docs/asyncstorage.html#multiremove) if you need to target only some keys.
* Errors should be caught and handled

## Good examples

```javascript
// 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.

```javascript
// 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.

```javascript
// 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');
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bamtech.gitbook.io/dev-standards/react-native/features/clean-logout.s.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
