Seamless auth example
Corporate partners can skip the embed login form. Watch isAuthenticated from useICCandleAuth(); if it is already true, reuse the session. Only when it is false should your backend call get-user-token and load /{locale}/sign-in with the returned tokens.
Do not put the corporate API key in the host page — call your route, which forwards the email with the key. API contract, rate limits, and query params: Seamless user authentication → Step 5.
import { ref, watch } from "vue";
import axios from "axios";
import { useICCandleAuth, WIDGET_RESULT_URL } from "@iccandle/vuejs-widget";
type UserTokenResponse = {
email: string;
created: boolean;
idToken?: string;
accessToken?: string;
refreshToken?: string;
expiresIn: number;
tokenType: "Bearer";
};
const { isAuthenticated } = useICCandleAuth();
const language = ref("en");
const theme = ref("light");
const iframeSrc = ref(
`${WIDGET_RESULT_URL}/${language.value}?theme=${theme.value}&header=true`,
);
const iframeLoaded = ref(false);
watch(
isAuthenticated,
(authenticated) => {
if (authenticated) return;
const fetchUserToken = async () => {
try {
const { data } = await axios.post<UserTokenResponse>(
"https://api.iccandle.ai/seamless-auth/get-user-token",
{
//replace with the end user's email
email: "test@email.com",
},
);
const idToken = data.idToken;
const accessToken = data.accessToken;
const refreshToken = data.refreshToken;
if (!idToken || !accessToken || !refreshToken) {
console.error("seamless-auth did not return tokens");
return;
}
const params = new URLSearchParams({
id_token: idToken,
access_token: accessToken,
refresh_token_param: refreshToken,
theme: theme.value,
header: "true",
});
iframeLoaded.value = false;
iframeSrc.value = `${WIDGET_RESULT_URL}/${language.value}/sign-in?${params.toString()}`;
} catch (error) {
console.error("seamless-auth failed", error);
}
};
void fetchUserToken();
},
{ immediate: true },
);
Call POST https://api.iccandle.ai/seamless-auth/get-user-token from your backend with the corporate API key.
Bind iframeSrc and iframeLoaded to your results iframe as in Get started.