I am trying to connect via websckets to HA from my Quasar/Vue3 application:
import {
getAuth,
createConnection,
subscribeEntities,
} from 'home-assistant-js-websocket';
async function connect() {
let auth;
try {
auth = await getAuth({
hassUrl: 'https://hass.example.com',
clientId: null,
authCode: 'eyXXXXU'
});
} catch (err) {
console.error(`HASS WS error: ${err}`);
return;
}
const connection = await createConnection({ auth });
subscribeEntities(connection, (ent) => console.log(ent));
}
This is a very initial stage, but I already stumbled upon an authentication error:
auth.js:47 POST https://hass.example.com/auth/token 400
tokenRequest @ auth.js:47
fetchToken @ auth.js:65
getAuth @ auth.js:146
connect @ temperatureOutside.vue:22
setup @ temperatureOutside.vue:39
callWithErrorHandling @ runtime-core.esm-bundler.js:155
setupStatefulComponent @ runtime-core.esm-bundler.js:7188
setupComponent @ runtime-core.esm-bundler.js:7143
mountComponent @ runtime-core.esm-bundler.js:5495
processComponent @ runtime-core.esm-bundler.js:5470
patch @ runtime-core.esm-bundler.js:5060
patchKeyedChildren @ runtime-core.esm-bundler.js:5977
patchChildren @ runtime-core.esm-bundler.js:5779
patchElement @ runtime-core.esm-bundler.js:5292
processElement @ runtime-core.esm-bundler.js:5140
patch @ runtime-core.esm-bundler.js:5057
patchKeyedChildren @ runtime-core.esm-bundler.js:5836
patchChildren @ runtime-core.esm-bundler.js:5779
patchElement @ runtime-core.esm-bundler.js:5292
processElement @ runtime-core.esm-bundler.js:5140
patch @ runtime-core.esm-bundler.js:5057
componentUpdateFn @ runtime-core.esm-bundler.js:5682
run @ reactivity.esm-bundler.js:185
instance.update @ runtime-core.esm-bundler.js:5716
callWithErrorHandling @ runtime-core.esm-bundler.js:155
flushJobs @ runtime-core.esm-bundler.js:388
Promise.then (async)
queueFlush @ runtime-core.esm-bundler.js:280
queueJob @ runtime-core.esm-bundler.js:274
reload @ runtime-core.esm-bundler.js:520
(anonymous) @ runtime-core.esm-bundler.js:558
(anonymous) @ temperatureOutside.vue:4
(anonymous) @ client.ts:435
(anonymous) @ client.ts:351
(anonymous) @ client.ts:206
queueUpdate @ client.ts:206
await in queueUpdate (async)
(anonymous) @ client.ts:74
handleMessage @ client.ts:72
(anonymous) @ client.ts:45
temperatureOutside.vue:29 HASS WS error: 2
Looking at the sources, error 2 is ERR_INVALID_AUTH
:
ERR_INVALID_AUTH
: This error will be raised if the url contains an authorization code that is no longer valid.
What does this mean, exactly? I created an authentication token from my account and this is what I used for authCode
. What is the proper token to use?