Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions airflow-core/src/airflow/ui/src/layouts/Nav/LogoutModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Text } from "@chakra-ui/react";
import React from "react";

import { ConfirmationModal } from "src/components/ConfirmationModal";
import { getRedirectPath } from "src/utils/links.ts";
import { TOKEN_STORAGE_KEY } from "src/utils/tokenHandler";

type LogoutModalProps = {
Expand All @@ -31,9 +32,7 @@ const LogoutModal: React.FC<LogoutModalProps> = ({ isOpen, onClose }) => (
<ConfirmationModal
header="Logout"
onConfirm={() => {
const baseHref = document.querySelector("head>base")?.getAttribute("href") ?? "";
const baseUrl = new URL(baseHref, globalThis.location.origin);
const logoutPath = new URL("api/v2/auth/logout", baseUrl).pathname;
const logoutPath = getRedirectPath("api/v2/auth/logout");

localStorage.removeItem(TOKEN_STORAGE_KEY);
globalThis.location.replace(logoutPath);
Expand Down
9 changes: 2 additions & 7 deletions airflow-core/src/airflow/ui/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import type { HTTPExceptionResponse } from "openapi/requests/types.gen";
import { ColorModeProvider } from "src/context/colorMode";
import { TimezoneProvider } from "src/context/timezone";
import { router } from "src/router";
import { getRedirectPath } from "src/utils/links.ts";

import { queryClient } from "./queryClient";
import { system } from "./theme";
Expand All @@ -44,13 +45,7 @@ axios.interceptors.response.use(
const params = new URLSearchParams();

params.set("next", globalThis.location.href);

const baseHref = document.querySelector("head>base")?.getAttribute("href") ?? "";

// Resolve the scheme-relative URL from the base relative to the current URL
const baseUrl = new URL(baseHref, globalThis.location.origin);

const loginPath = new URL("api/v2/auth/login", baseUrl).pathname;
const loginPath = getRedirectPath("api/v2/auth/login");

globalThis.location.replace(`${loginPath}?${params.toString()}`);
}
Expand Down
7 changes: 7 additions & 0 deletions airflow-core/src/airflow/ui/src/utils/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ export const getTaskInstanceLinkFromObj = ({
mapIndex: number;
taskId: string;
}) => `/dags/${dagId}/runs/${dagRunId}/tasks/${taskId}${mapIndex >= 0 ? `/mapped/${mapIndex}` : ""}`;

export const getRedirectPath = (targetPath: string): string => {
const baseHref = document.querySelector("head > base")?.getAttribute("href") ?? "";
const baseUrl = new URL(baseHref, globalThis.location.origin);

return new URL(targetPath, baseUrl).pathname;
};