I have an application using the teller.io API. I have to import a script from them to initiate authentication within my react app, as they have no react library.
After adding the script to the DOM, I have to use a function from it. However, React won't recognize the function as it's only defined at runtime when the script is added.
The following is my solution, and it works, but I know this cannot be a good way to accomplish this so if anyone can recommend a proper solution that'd be amazing.
useEffect(() => {
const script = document.createElement("script");
script.src = "https://cdn.teller.io/connect/connect.js";
script.async = true;
document.head.appendChild(script);
var tellerConnect = window.TellerConnect.setup({
applicationId: "Your application ID e.g app_xxxxxx",
onInit: function() {
console.log("Teller Connect has initialized");
},
// Part 3. Handle a successful enrollment's accessToken
onSuccess: function(enrollment) {
console.log("User enrolled successfully", enrollment.accessToken);
},
onExit: function() {
console.log("User closed Teller Connect");
}
});
var el = document.getElementById("myButton");
el.addEventListener("click", function() {
// tellerConnect.open();
});
}, []);
Line 6, with the "window.TellerConnect.setup is what I'd like to fix/replace with a more proper solution.
Teller.io docs for this script/setup can be found at: Teller Connect
Thanks in advance!
setup...