Authenticating users
bobissict opened this issue · 3 comments
bobissict commented
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?
B3nnyL commented
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
B3nnyL commented
@bobissict Does rumtime setup work for you?