Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// We don't load the component when onboarding is done
document.location.assign("/");
return;
}
const steps: OnboardingStep[] = await response.json();
if (steps.every((step) => step.done)) {
// Onboarding is done!
document.location.assign("/");
return;
}
if (steps[0].done) {
// First step is already done, so we need to get auth somewhere else.
const auth = await getAuth({
hassUrl,
});
history.replaceState(null, "", location.pathname);
await this._connectHass(auth);
}
this._steps = steps;
} catch (err) {
alert("Something went wrong loading onboarding, try refreshing");
}
}
private async _handleStepDone(
ev: HASSDomEvent>
) {
const stepResult = ev.detail;
this._steps = this._steps!.map((step) =>
step.step === stepResult.type ? { ...step, done: true } : step
);
if (stepResult.type === "user") {
const result = stepResult.result as OnboardingResponses["user"];
this._loading = true;
try {
const auth = await getAuth({
hassUrl,
authCode: result.auth_code,
});
await this._connectHass(auth);
} catch (err) {
alert("Ah snap, something went wrong!");
location.reload();
} finally {
this._loading = false;
}
} else if (stepResult.type === "core_config") {
// We do nothing
} else if (stepResult.type === "integration") {
const result = stepResult.result as OnboardingResponses["integration"];
this._loading = true;
private async _handleConnectMessage(msg: ConnectMessage) {
let auth;
try {
auth = await getAuth({
loadTokens: async () => ({
hassUrl: msg.hassUrl,
clientId: msg.clientId,
refresh_token: msg.refreshToken,
access_token: "",
expires: 0,
expires_in: 0,
}),
});
} catch (err) {
this._error = this._getErrorMessage(err);
return;
}
let connection;
try {
connection = await createConnection({ auth });