diff options
| author | Shravya Ramesh <shravs1208@gmail.com> | 2021-04-09 12:20:25 -0700 |
|---|---|---|
| committer | Shravya Ramesh <shravs1208@gmail.com> | 2021-04-09 12:20:25 -0700 |
| commit | b967bd77710bce7b92ae0863df52cce345abd4e4 (patch) | |
| tree | e492b323712701f02339257beecc5279b050d764 /src/utils | |
| parent | d601b6dcf93dc1e326a9e79c5b19db6bcdaedbdf (diff) | |
connecting user during login
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/messages.ts | 4 | ||||
| -rw-r--r-- | src/utils/users.ts | 12 |
2 files changed, 11 insertions, 5 deletions
diff --git a/src/utils/messages.ts b/src/utils/messages.ts index 0ef56edb..b2162d34 100644 --- a/src/utils/messages.ts +++ b/src/utils/messages.ts @@ -92,7 +92,7 @@ export const connectChatAccount = async ( ) => { try { const chatToken = await AsyncStorage.getItem('chatToken'); - chatClient.connectUser( + await chatClient.connectUser( { id: loggedInUserId, }, @@ -100,7 +100,7 @@ export const connectChatAccount = async ( ); dispatch(updateChatClientReady(true)); } catch (err) { - dispatch(updateChatClientReady(true)); + dispatch(updateChatClientReady(false)); console.log('Error while connecting user to Stream: ', err); } }; diff --git a/src/utils/users.ts b/src/utils/users.ts index 22c1c1f0..ec09198d 100644 --- a/src/utils/users.ts +++ b/src/utils/users.ts @@ -12,18 +12,17 @@ import { logout, } from '../store/actions'; import {NO_SOCIAL_ACCOUNTS} from '../store/initialStates'; -import {userLoggedIn} from '../store/reducers'; import {loadUserMomentCategories} from './../store/actions/momentCategories'; import {loadUserX} from './../store/actions/userX'; import {AppDispatch} from './../store/configureStore'; import {RootState} from './../store/rootReducer'; import { ProfilePreviewType, - CategoryPreviewType, ProfileInfoType, ScreenType, UserType, } from './../types/types'; +import {connectChatAccount} from './messages'; const loadData = async (dispatch: AppDispatch, user: UserType) => { await Promise.all([ @@ -44,7 +43,11 @@ const loadData = async (dispatch: AppDispatch, user: UserType) => { * @param dispatch This is the dispatch object from the redux store * @param user The user if at all any */ -export const userLogin = async (dispatch: AppDispatch, user: UserType) => { +export const userLogin = async ( + dispatch: AppDispatch, + user: UserType, + chatClient?, +) => { try { let localUser = {...user}; if (!user.userId) { @@ -64,6 +67,9 @@ export const userLogin = async (dispatch: AppDispatch, user: UserType) => { AsyncStorage.setItem('username', user.username), ]); } + if (chatClient) { + connectChatAccount(localUser.userId, chatClient, dispatch); + } await loadData(dispatch, localUser); } catch (error) { console.log(error); |
