Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions src/panels/my/ha-panel-my.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ export const getMyRedirects = (hasSupervisor: boolean): Redirects => ({
component: "lovelace",
redirect: "/config/lovelace/resources",
},
oauth2_authorize_callback: {
redirect: "/auth/external/callback",
navigate_outside_spa: true,
params: {
error: "string?",
code: "string?",
state: "string",
},
},
people: {
component: "person",
redirect: "/config/person",
Expand Down Expand Up @@ -214,11 +223,13 @@ const getRedirect = (
hasSupervisor: boolean
): Redirect | undefined => getMyRedirects(hasSupervisor)?.[path];

export type ParamType = "url" | "string";
export type ParamType = "url" | "string" | "string?";

export type Redirects = { [key: string]: Redirect };
export interface Redirect {
redirect: string;
// Set to True to use browser redirect instead of frontend navigation
navigate_outside_spa?: boolean;
component?: string;
params?: {
[key: string]: ParamType;
Expand Down Expand Up @@ -277,7 +288,11 @@ class HaPanelMy extends LitElement {
return;
}

navigate(url, { replace: true });
if (this._redirect.navigate_outside_spa) {
location.assign(url);
} else {
navigate(url, { replace: true });
}
}

protected render() {
Expand Down Expand Up @@ -345,17 +360,20 @@ class HaPanelMy extends LitElement {
return "";
}
const resultParams = {};
Object.entries(this._redirect!.params || {}).forEach(([key, type]) => {
for (const [key, type] of Object.entries(this._redirect!.params || {})) {
if (!params[key] && type.endsWith("?")) {
continue;
}
if (!params[key] || !this._checkParamType(type, params[key])) {
throw Error();
}
resultParams[key] = params[key];
});
}
return `?${createSearchParam(resultParams)}`;
}

private _checkParamType(type: ParamType, value: string) {
if (type === "string") {
if (type === "string" || type === "string?") {
return true;
}
if (type === "url") {
Expand Down