Hey @Amin Azimi
Paul, weekend support engineer here 👋
You're encountering a known issue where Intercom's Messenger fails to properly transition from an anonymous to an identified user session in single-page apps like Next.js. When a user opens the chat while unauthenticated and then logs in without a full page reload, Intercom may still retain the anonymous session internally, even if you call shutdown() and re-initialize it.
This leads to errors like “Sorry, we couldn’t find your messages” because the Messenger is trying to access a conversation tied to the old session. To fix this, ensure you call shutdown() right before the login process begins, and only reinitialize Intercom after the login is complete and user data is fully available. If issues persist, a one-time window.location.reload() after login can fully reset the session and Messenger state.
Hey there!
We had the same issue where Intercom showed “Sorry, we couldn’t find your messages” after a user opened the chat while logged out, then logged in, without reloading the page.
When chat is opened before login, Intercom creates an anonymous session. Even after calling shutdown() and reinitializing, it may not fully reset the session without a reload.
Our solution:
We check if the user has changed (e.g., just logged in). If so, we:
-
Shut down Intercom
-
Boot it fresh with just the app ID
-
After a short delay, update it with the logged-in user's details
This cleanly resets the session without needing a full page reload.
Code Snippet:
useEffect(() => {
const userId = user?.id || null;
const hasUserChanged = prevUserId.current && prevUserId.current !== userId;
if (hasUserChanged) {
Intercom.shutdown(); // Close previous session
Intercom.boot({ app_id: intercomAppId }); // Start fresh
setTimeout(() => {
Intercom.update({
app_id: intercomAppId,
name: user.name,
email: user.email,
user_hash: user.intercom_hash,
});
}, 100); // Delay to let Intercom reset properly
prevUserId.current = userId;
}
}, [user]);
This fully fixed the issue in our Next.js app. Hope it helps someone else!