Skip to content

Use the token

Pass the token from your backend as token, and a getToken function that fetches a fresh one. The widget calls getToken when the token expires or is rejected; return null to sign the user out.

const fetchToken = () =>
fetch("/snipet-token")
.then((r) => (r.ok ? r.json() : null))
.then((r) => r?.token ?? null);
SnipetWidget.init({
apiUrl: "https://snipet.example.com",
agentId: "<your agent id>",
token: await fetchToken(),
getToken: fetchToken,
});

When your user signs in after the page has loaded, call setToken(token). When they sign out, call setToken(null) so the next person on the same browser doesn’t see their conversations.

A token used from a browser is only accepted from the app’s allowed origins, when the app lists any. Requests from servers carry no origin and aren’t checked.