Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
connection.then(({ conn }) => {
localStorage.removeItem('auth_triggered');
this.setState({ connected: true });
conn.removeEventListener('ready', this.eventHandler);
conn.addEventListener('ready', this.eventHandler);
subscribeConfig(conn, this.updateConfig);
subscribeEntities(conn, this.updateEntities);
getUser(conn).then(user => {
console.log('Logged into Home Assistant as', user.name);
sessionStorage.setItem('hass_id', user.id);
});
connection = conn;
});
})();
hassUrl: props.url,
saveTokens: saveTokens,
loadTokens: () => Promise.resolve(loadTokens())
});
connection = await createConnection({ auth });
} catch (err) {
throw err;
}
}
props.setConnected(true);
connection.removeEventListener('ready', eventHandler);
connection.addEventListener('ready', eventHandler);
props.setAuth(auth);
subscribeConfig(connection, updateConfig);
subscribeEntities(connection, updateEntites);
getUser(connection).then((user: HassUser) => {
console.log('Logged into Home Assistant as', user.name);
});
})();
}, [props, updateConfig, updateEntites]);
export const subscribeUser = (conn, onChange) =>
createCollection("_usr", (conn_) => getUser(conn_), null, conn, onChange);
() => getUser(conn) as Promise,
undefined