Hi, I have an SPA and so have to log users in asychronously. For some reason I keep getting UNAUTHORIZED_API_CALL messages. Here is my flow
- On page load, javascript is embedded
- On User login setAttributes is called (See Example 1 below) (At this point I receive the UNAUTHORIZED_API_CALL error)
- When a user is logged out, logout() is called
- When a new user is logged in, setAttributes is called again
Example 1 - User login
this.tawkAPI.setAttributes(
{
'userId': currentUser.Id,
'name': currentUser.Name,
'email': currentUser.Email,
'hash': hash
},
(error) => {
console.error("set attribute error", error);
});
Example 2: Hash creation
var tawkApiKey = "xxxxx";
using (var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(tawkApiKey)))
{
byte[] hashBytes = hmac.ComputeHash(Encoding.UTF8.GetBytes(user.Id.ToString()));
return this.Ok(BitConverter.ToString(hashBytes).Replace("-", "").ToLower());
}