'How switch a visitor to a user in intercom when logged in Next.js?

I have a website with pages for users and visitors. I Show intercom to visitors using the installation script from intercom documentation installation script for visitors

Intercom for visitor is showed during signup pages, then when a visitor is registered is redirected to user pages and i switch to the script for users using 'shutdown' to show intercom for users.

window.intercom.shutdown()

Then i restart intercom with 'boot'

window.intercomSettings = {
  app_id: APP_ID,
  api_base: 'https://api-iam.intercom.io',
}
window.Intercom('boot', {
  email,
  name,
  stack: 'b2b',
  user_id: `b2b-${id}`,
})

Intercom chat for visitors disapear but user chat don't show. Which is the best way to switch from visitor to user?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source