How to maintain login session while visiting different pages?

I have initialized and login with chat UI. Visiting another page causing a page to reload hence chat is not working.

I am using https://github.com/cometchat-pro-samples/react-chat-ui-kit-app
when i visit another page the chat feature stop working. How to maintain this across all the pages ?

am i getting any help over this ?

Hi @amitchauh4n,

Could you please let me know visiting which another page causes the chat to stop working?

Hi @priyadarshini.nadar
My react project contains multi page. So after login success i am calling init method and then login the user which is successful. After that we are redirecting to our home page where chat ui is not working.
It means if i reload the page and chat will stop working.

@amitchauh4n,

Can you please check what is the response of CometChat.getLoggedinUser() method?

Please refer below link for implementation of this method…

Hi @priyadarshini.nadar on the same page chat is working in which init and login was called, but when i navigate to other page it’s not.
however i am getting this error
message: "Cannot read property 'get' of undefined"

ok i understand i have resolved. thanks for your help and time.

Hello @amitchauh4n,

Glad that you could resolve it on your end. Can you please share the solution which helped you resolve this issue. It would be helpful for other users facing the similar issue.

1 Like

My implementation was wrong actually. I was initialising Cometchat inside my login component, but it should be initialised inside the main.js or common file which is firstly loaded to browser or can be accessible to every pages. That’s why Cometchat object was not available to my other pages so chat was not working.

3 Likes