B3nnyL/react-zendesk

Authenticating users

bobissict opened this issue · 3 comments

Thanks for a great plugin. Really helpful :)

I'm trying to work out where to put this code to authenticate users:

window.zESettings = {
 webWidget: {
   authenticate: {
     chat: {
       jwtFn: function(callback) { 
         fetch('JWT_TOKEN_ENDPOINT').then(function(res) {
            res.text().then(function(jwt) {
             callback(jwt);
            });
          });
        }
      } 
    }
  }
};

I've tried putting it in the zendesk settings object like this:

const zendeskSetting = {
      authenticate: {
        chat: {
          jwtFn(callback) {
            callback(user.zendeskToken);
          },
        },
      },
    };

but then I get an error:

Zendesk Chat Web SDK: Error: setVisitorInfo: Web SDK is not initialized yet. Please ensure that you call zChat.init() and wait for the connection to be established before calling this method

Could anyone point me in the right direction on how to authenticate users with react-zendesk?

It seems you setup authentication before chat session initialization. Have you tried update the settings at run-time by

ZendeskAPI("webWidget", "updateSettings", {... your web widget setting});

https://developer.zendesk.com/embeddables/docs/widget/core#updatesettings

@bobissict Does rumtime setup work for you?

@B3nnyL I actually decided against using zendesk for different reasons so didn't get a chance to try the fix.

Thanks for the feedback though 💪🏻