How to reset customer's identityin a FcWidget?

Hello,

Problem I face:
I am implementing the FcWidget to my page. I would like to have the FcWidget service available to the customers before and after a customer has logged in. My problem is that when the user (customer A) has been created on Freshchat, the FcWidget is always associated with that account (customer A), even when the customer has logged out or even logged in as another customer (customer B) on my site.

For switching between different logged in users, I guess storing the restoreId is the solution (am I right?)

But for logged out customers, I want the FcWidget to consider the customers as anonymous user and I have no idea how to do that. I tried to delete the browser history, but it doesn’t clear the association.

My code:

    let widgetConfig: FreshChatConfig = {
      token: TOKEN,
      host: HOST,
      restoreId: null
    };
    
    const { firstName, lastName } = this.userData;
    if (firstName || lastName) {
      widgetConfig = { ...widgetConfig, firstName, lastName };
    }

    window.fcWidget.init(widgetConfig);

    console.log(
      await window.fcWidget.user.get()  // it always return the user object even when the user is not logged in: { data: { firstName: "Max", lastName: "Smith", …}, success: true, status: 200}
    );
  }

Any help will be appriciated. Thanks.

2 Likes

hey, any suggestions?

Hi @shan,

You can use window.fcWidget.user.clear() to reset the widget. The sample code is below.

window.fcWidget.user.clear().then(function() {
  console.log('User cleared');
  }, function() {
    console.log("User Not cleared");
  });

We usually recommend this action take place on click of Logout, and on the success of this complete the app’s logout action.

Let me know if this helps.

2 Likes

Resetting a customer’s identity in an FcWidget typically involves clearing or updating the stored user session. Depending on the platform and API you’re using, this can usually be done by calling a reset or logout function provided by the widget’s SDK.

For example, in Freshchat’s FCWidget, you can reset the user identity with:

FCWidget.user.clear();

This ensures that the previous user session is removed, allowing a new user to be identified when the widget is reloaded. If you’re using a different framework or version, checking the official documentation or API reference for the correct method would be advisable.

Could you provide more details on the specific implementation you’re working with? That would help in giving a more precise solution!