1
0
mirror of https://github.com/home-assistant/frontend.git synced 2026-04-19 00:12:51 +01:00

Add ingress session validation (#7610)

This commit is contained in:
Paulus Schoutsen
2020-11-06 23:01:29 +01:00
committed by GitHub
parent cc1d50491b
commit 7e2db0aa4e
4 changed files with 62 additions and 22 deletions

View File

@@ -0,0 +1,26 @@
import { HomeAssistant } from "../../types";
import { HassioResponse } from "./common";
import { CreateSessionResponse } from "./supervisor";
export const createHassioSession = async (hass: HomeAssistant) => {
const response = await hass.callApi<HassioResponse<CreateSessionResponse>>(
"POST",
"hassio/ingress/session"
);
document.cookie = `ingress_session=${
response.data.session
};path=/api/hassio_ingress/;SameSite=Strict${
location.protocol === "https:" ? ";Secure" : ""
}`;
return response.data.session;
};
export const validateHassioSession = async (
hass: HomeAssistant,
session: string
) =>
await hass.callApi<HassioResponse<null>>(
"POST",
"hassio/ingress/validate_session",
{ session }
);

View File

@@ -111,18 +111,6 @@ export const fetchHassioLogs = async (
return hass.callApi<string>("GET", `hassio/${provider}/logs`);
};
export const createHassioSession = async (hass: HomeAssistant) => {
const response = await hass.callApi<HassioResponse<CreateSessionResponse>>(
"POST",
"hassio/ingress/session"
);
document.cookie = `ingress_session=${
response.data.session
};path=/api/hassio_ingress/;SameSite=Strict${
location.protocol === "https:" ? ";Secure" : ""
}`;
};
export const setSupervisorOption = async (
hass: HomeAssistant,
data: SupervisorOptions