Skip to content

Commit

Permalink
only use refreshToken
Browse files Browse the repository at this point in the history
  • Loading branch information
SanterreJo committed Apr 12, 2024
1 parent c41bb94 commit 6363487
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
13 changes: 8 additions & 5 deletions homebridge-ui/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@
]
});
window.open(href, "_blank");

const { refreshToken } = await callback;
const { refreshToken, expiresIn, refreshTokenExpiresIn } = await callback;
let pluginConfigBlocks = await homebridge.getPluginConfig();
pluginConfigBlocks = pluginConfigBlocks.map((block) => {
block.refreshToken = refreshToken;
return block;
});
await homebridge.updatePluginConfig(pluginConfigBlocks);
await homebridge.savePluginConfig();
homebridge.toast.success("Successfully authenticated with Hilo");

const refreshTokenInput = document.querySelector('input[name="refreshToken"]');
refreshTokenInput.value = refreshToken;
}
</script>
2 changes: 1 addition & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ let _api: API;
export const setApi = (api: API) => {
_api = api;
};
export const getapi = () => _api;
export const getApi = () => _api;
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { PlatformConfig } from "homebridge";
export type HiloConfig = PlatformConfig & {
noChallengeSensor: boolean;
plannedHours: number;
refreshToken: string;
};

const defaultConfig: Partial<HiloConfig> = {
noChallengeSensor: false,
plannedHours: 2,
refreshToken: "",
};

let _config: HiloConfig;
Expand Down
2 changes: 1 addition & 1 deletion src/hilo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Hilo implements DynamicPlatformPlugin {
) {
setConfig(config as HiloConfig);
this.config = getConfig();
if (!this.config.accessToken) {
if (!this.config.refreshToken) {
this.log.error("Please login with hilo in the plugin configuration page");
return;
}
Expand Down
2 changes: 2 additions & 0 deletions src/hiloApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import axios, { AxiosRequestConfig } from "axios";
import { decode } from "jsonwebtoken";
import { getConfig } from "./config";
import { getLogger } from "./logger";
import { getApi } from "./api";

let accessToken: string | undefined;
let wsAccessToken: string | undefined;
Expand All @@ -20,6 +21,7 @@ const renewTokens = ({
newAccessToken: string;
expiresIn: number;
}) => {
console.log(getApi().user.configPath());
accessToken = newAccessToken;
refreshToken = newRefreshToken;
setupAutoRefreshToken(expiresIn);
Expand Down

0 comments on commit 6363487

Please sign in to comment.