Enable Authentication for visitors in Web Widget
Hi Team,
We have integrated web widget(chat) in our Angular 7 app. We did go through the mentioned article https://chat.zendesk.com/hc/en-us/articles/360001301627-Enabling-authenticated-visitors-in-the-Web-Widget about how to enable authentication for visitors.
ISSUE: When the below code snippet is run on APPLICATION PAGE LOAD it runs fine, generates the token and authenticates the user.This tells me that the code sample works fine.
However during route changes/page is refreshed, the below code snippet is not executed. The jwtFn function is never called. We have placed this in the root component which gets fired on every route change. Please suggest.
CODE SNIPPET Used for authentication:
this.window['zESettings'] = {
webWidget: {
authenticate: {
chat: {
jwtFn: (callback) => {
this.apiService.ssoPost(this.zendeskAPIURL, null, null).subscribe((response) => {
console.log('Response from Zendesk Chat API', response.zendeskToken);
callback(response.zendeskToken);
});
},
},
},
},
};
-
Hi Vikas, we don't listen for window changes, instead you will need to call updateSettings when a route has changed or the page is refreshed.
-
Hi Daniel,
We are using updateSettings to authenticate the user after he logs in . Unfortunately the jwtFn callback does not get called on updateSettings.
I see the color is changed which confirms that the updateSettings is being run.
Here is the sample code:
this.zE('webWidget', 'updateSettings', {
webWidget: {
color: {theme: '#FFFF00'},
authenticate: {
jwt: jwtToken,
chat: {
suppress: false,
jwtFn: function (callback) {
this.apiService.ssoPost(this.zendeskAPIURL, null, null).subscribe((response) => {
console.log('Response from Zendesk Chat API - Identify', response.zendeskToken);
console.log('Call back', callback);
callback(jwtToken);
});
},
},
},
},
}); -
Hi Vikas, apologies I may have misunderstood your initial question. Correct, you can't use updateSettings in combination with authenticate to renew the JWT. There is an existing way to renew the JWT for Chat authentication which I believe you're aware of and is described in this document. We plan to provide a similar solution to renew the JWT for Support authentication, i'll provide an update here when we have an ETA.
-
Hi Daniel, I am running into the same issue as described above.
Using an SPA Framework (such as angular) means that we need to be able to 'refresh' the authentication method for the web widget / chat AFTER a user logs in, but without a page reload. Is this possible?
-
Hi Brian, yes this is now possible. You can now refresh the authentication method for an SPA by using the jwtFn, similar to the code snippet here.
Note: The code in the example would authenticate with both chat and help center.
Please sign in to leave a comment.
5 Comments