Our product uses NextJS 13.4.9 and we are trying to integrate intercom messenger. In our _app.js we are using the useEffect below to check if the user is logged in or not (guest). What’s happening is that when he is a guest everything works well. When he logs in and opens the launcher for the first time it shows the message “Something’s gone wrong”. After a refresh everything works.
We have seen other related topics and they don’t work in our case. We have also used shutdown in login/logout and nothing works. Something worth mentioning is that after the login when the user clicks the launcher the Intercom’s localStorage is cleared and the intercom-session-[id] cookie as well. After a refresh all works well. Now we don’t know if this is the cause.
import { Intercom, shutdown } from '@intercom/messenger-js-sdk';
useEffect(() => {
if (process.env.hasIntercomMessenger && process.env.intercomMessengerAppId) {
if (user?.customerServiceIntegratorId) {
// for logged in user
Intercom({
app_id: process.env.intercomMessengerAppId,
user_id: user.customerServiceIntegratorId,
created_at: Math.floor(new Date(user.createdAt).getTime() / 1000),
});
} else {
// for guest user
Intercom({
app_id: process.env.intercomMessengerAppId,
});
}
}
return () => {
shutdown();
};
}, [user?.customerServiceIntegratorId]);