Using the Access Token in Your Frontend
Once your backend endpoint is ready, your frontend retrieves tokens by calling it through the .onGetAuth callback.
onGetAuth Callback
The .onGetAuth() callback should invoke your server’s auth endpoint and return a promise that resolves with the token.
Example (Async/Await)
const halosight = new HalosightEmbed({
// Component setup here
})
.onRegister(() => {
// On register actions
})
.onGetAuth(async () => {
const response = await fetch('https://YOUR_SERVER/getapitoken', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
});
return response.json();
});
Example (.then / .catch)
const halosight = new HalosightEmbed({
// Component setup here
})
.onRegister(() => {
// On register actions
})
.onGetAuth(() => {
return fetch('https://YOUR_SERVER/getapitoken', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
})
.then((res) => res.json())
.catch((err) => {
throw new Error('Auth failed: ' + err);
});
});