mirror of
https://github.com/home-assistant/frontend.git
synced 2025-12-19 18:28:42 +00:00
Always store token when using develop and serve (#28179)
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import type { AuthData } from "home-assistant-js-websocket";
|
import type { AuthData } from "home-assistant-js-websocket";
|
||||||
import { extractSearchParam } from "../url/search-params";
|
import { extractSearchParam } from "../url/search-params";
|
||||||
|
import { hassUrl } from "../../data/auth";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
@@ -30,7 +31,11 @@ export function askWrite() {
|
|||||||
export function saveTokens(tokens: AuthData | null) {
|
export function saveTokens(tokens: AuthData | null) {
|
||||||
tokenCache.tokens = tokens;
|
tokenCache.tokens = tokens;
|
||||||
|
|
||||||
if (!tokenCache.writeEnabled && extractSearchParam("storeToken") === "true") {
|
if (
|
||||||
|
!tokenCache.writeEnabled &&
|
||||||
|
(extractSearchParam("storeToken") === "true" ||
|
||||||
|
hassUrl !== `${location.protocol}//${location.host}`)
|
||||||
|
) {
|
||||||
tokenCache.writeEnabled = true;
|
tokenCache.writeEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
||||||
|
|
||||||
let askWrite;
|
let askWrite;
|
||||||
|
|
||||||
|
const HASS_URL = `${location.protocol}//${location.host}`;
|
||||||
|
|
||||||
describe("token_storage.askWrite", () => {
|
describe("token_storage.askWrite", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.stubGlobal("__HASS_URL__", HASS_URL);
|
||||||
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
vi.resetModules();
|
vi.resetModules();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,9 +4,12 @@ import { FallbackStorage } from "../../../test_helper/local-storage-fallback";
|
|||||||
|
|
||||||
let saveTokens;
|
let saveTokens;
|
||||||
|
|
||||||
|
const HASS_URL = `${location.protocol}//${location.host}`;
|
||||||
|
|
||||||
describe("token_storage.saveTokens", () => {
|
describe("token_storage.saveTokens", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
window.localStorage = new FallbackStorage();
|
window.localStorage = new FallbackStorage();
|
||||||
|
vi.stubGlobal("__HASS_URL__", HASS_URL);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import { describe, it, expect, test, vi, afterEach, beforeEach } from "vitest";
|
|||||||
import type { AuthData } from "home-assistant-js-websocket";
|
import type { AuthData } from "home-assistant-js-websocket";
|
||||||
import { FallbackStorage } from "../../../test_helper/local-storage-fallback";
|
import { FallbackStorage } from "../../../test_helper/local-storage-fallback";
|
||||||
|
|
||||||
|
const HASS_URL = `${location.protocol}//${location.host}`;
|
||||||
|
|
||||||
describe("token_storage", () => {
|
describe("token_storage", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.stubGlobal(
|
vi.stubGlobal(
|
||||||
@@ -11,6 +13,7 @@ describe("token_storage", () => {
|
|||||||
writeEnabled: undefined,
|
writeEnabled: undefined,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
vi.stubGlobal("__HASS_URL__", HASS_URL);
|
||||||
window.localStorage = new FallbackStorage();
|
window.localStorage = new FallbackStorage();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user