From c694abb1fd4555971dbdcec9e5c5ef1ff2269b17 Mon Sep 17 00:00:00 2001 From: "lluis@protofy.xyz" Date: Thu, 31 Oct 2024 13:56:54 +0100 Subject: [PATCH] manage the tokens on device side --- .../protolib/src/bundles/devices/devices/devicesSchemas.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/protolib/src/bundles/devices/devices/devicesSchemas.ts b/packages/protolib/src/bundles/devices/devices/devicesSchemas.ts index 296f0b856..4f6b5d83c 100644 --- a/packages/protolib/src/bundles/devices/devices/devicesSchemas.ts +++ b/packages/protolib/src/bundles/devices/devices/devicesSchemas.ts @@ -176,6 +176,10 @@ export class DevicesModel extends ProtoModel { console.log(response1.error) return; } + const res = await API.get("/api/core/v1/tokens/device/create?deviceId=" + this.data.name) + if (res.isError) { + console.log(res.error) + } console.log("---------deviceDefinition----------", deviceDefinition) deviceDefinition.board = response1.data const jsCode = deviceDefinition.config.components; @@ -183,6 +187,9 @@ export class DevicesModel extends ProtoModel { const deviceCode = 'device(' + jsCode.replace(/;/g, "") + ')'; console.log("-------DEVICE CODE------------", deviceCode) const deviceObj = eval(deviceCode) + if(res.data.token){ + deviceObj.setCredentials({mqtt: {username: this.data.name, password: res.data.token}}) + } const componentsTree = deviceObj.getComponentsTree(this.data.name, deviceDefinition) yaml = deviceObj.dump("yaml").replace(/'@/g,"").replace(/@'/g,"")