mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 08:16:36 +00:00
Fix keep me logged in (#10835)
This commit is contained in:
parent
7039bae9be
commit
faccb12430
@ -37,6 +37,25 @@ declare global {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const clearUrlParams = () => {
|
||||||
|
// Clear auth data from url if we have been able to establish a connection
|
||||||
|
if (location.search.includes("auth_callback=1")) {
|
||||||
|
const searchParams = new URLSearchParams(location.search);
|
||||||
|
// https://github.com/home-assistant/home-assistant-js-websocket/blob/master/lib/auth.ts
|
||||||
|
// Remove all data from QueryCallbackData type
|
||||||
|
searchParams.delete("auth_callback");
|
||||||
|
searchParams.delete("code");
|
||||||
|
searchParams.delete("state");
|
||||||
|
searchParams.delete("storeToken");
|
||||||
|
const search = searchParams.toString();
|
||||||
|
history.replaceState(
|
||||||
|
null,
|
||||||
|
"",
|
||||||
|
`${location.pathname}${search ? `?${search}` : ""}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const authProm = isExternal
|
const authProm = isExternal
|
||||||
? () =>
|
? () =>
|
||||||
import("../external_app/external_auth").then(({ createExternalAuth }) =>
|
import("../external_app/external_auth").then(({ createExternalAuth }) =>
|
||||||
@ -52,23 +71,7 @@ const authProm = isExternal
|
|||||||
const connProm = async (auth) => {
|
const connProm = async (auth) => {
|
||||||
try {
|
try {
|
||||||
const conn = await createConnection({ auth });
|
const conn = await createConnection({ auth });
|
||||||
// Clear auth data from url if we have been able to establish a connection
|
clearUrlParams();
|
||||||
if (location.search.includes("auth_callback=1")) {
|
|
||||||
const searchParams = new URLSearchParams(location.search);
|
|
||||||
// https://github.com/home-assistant/home-assistant-js-websocket/blob/master/lib/auth.ts
|
|
||||||
// Remove all data from QueryCallbackData type
|
|
||||||
searchParams.delete("auth_callback");
|
|
||||||
searchParams.delete("code");
|
|
||||||
searchParams.delete("state");
|
|
||||||
searchParams.delete("storeToken");
|
|
||||||
const search = searchParams.toString();
|
|
||||||
history.replaceState(
|
|
||||||
null,
|
|
||||||
"",
|
|
||||||
`${location.pathname}${search ? `?${search}` : ""}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return { auth, conn };
|
return { auth, conn };
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
if (err !== ERR_INVALID_AUTH) {
|
if (err !== ERR_INVALID_AUTH) {
|
||||||
@ -85,6 +88,7 @@ const connProm = async (auth) => {
|
|||||||
}
|
}
|
||||||
auth = await authProm();
|
auth = await authProm();
|
||||||
const conn = await createConnection({ auth });
|
const conn = await createConnection({ auth });
|
||||||
|
clearUrlParams();
|
||||||
return { auth, conn };
|
return { auth, conn };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -127,7 +127,9 @@ export class HassRouterPage extends ReactiveElement {
|
|||||||
|
|
||||||
// Update the url if we know where we're mounted.
|
// Update the url if we know where we're mounted.
|
||||||
if (route) {
|
if (route) {
|
||||||
navigate(`${route.prefix}/${result}`, { replace: true });
|
navigate(`${route.prefix}/${result}${location.search}`, {
|
||||||
|
replace: true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,9 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
|
|||||||
const path = curPath();
|
const path = curPath();
|
||||||
|
|
||||||
if (["", "/"].includes(path)) {
|
if (["", "/"].includes(path)) {
|
||||||
navigate(`/${getStorageDefaultPanelUrlPath()}`, { replace: true });
|
navigate(`/${getStorageDefaultPanelUrlPath()}${location.search}`, {
|
||||||
|
replace: true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
this._route = {
|
this._route = {
|
||||||
prefix: "",
|
prefix: "",
|
||||||
|
@ -698,7 +698,7 @@ class HUIRoot extends LitElement {
|
|||||||
|
|
||||||
private _navigateToView(path: string | number, replace?: boolean) {
|
private _navigateToView(path: string | number, replace?: boolean) {
|
||||||
if (!this.lovelace!.editMode) {
|
if (!this.lovelace!.editMode) {
|
||||||
navigate(`${this.route!.prefix}/${path}`, { replace });
|
navigate(`${this.route!.prefix}/${path}${location.search}`, { replace });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
navigate(`${this.route!.prefix}/${path}?${addSearchParam({ edit: "1" })}`, {
|
navigate(`${this.route!.prefix}/${path}?${addSearchParam({ edit: "1" })}`, {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user