From bdccd7ae173c0342350c613b6247f2cfb0b9fe92 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Tue, 6 Apr 2021 14:58:25 -0400 Subject: disconnect user --- src/store/actions/user.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/store') diff --git a/src/store/actions/user.ts b/src/store/actions/user.ts index e7d985ac..4faa2206 100644 --- a/src/store/actions/user.ts +++ b/src/store/actions/user.ts @@ -1,4 +1,5 @@ import AsyncStorage from '@react-native-community/async-storage'; +import {StreamChat} from 'stream-chat'; import {Action, ThunkAction} from '@reduxjs/toolkit'; import { getProfilePic, @@ -164,13 +165,16 @@ export const updateReplyPosted = ( } }; -export const logout = (): ThunkAction< - Promise, - RootState, - unknown, - Action -> => async (dispatch) => { +export const logout = ( + client?: StreamChat, +): ThunkAction, RootState, unknown, Action> => async ( + dispatch, +) => { try { + // do our best effort here to gracefully disconnect the user + if (client) { + await client.disconnectUser(); + } await AsyncStorage.clear(); dispatch({type: userLoggedIn.type, payload: {userId: '', username: ''}}); } catch (error) { -- cgit v1.2.3-70-g09d2