Fix auth when serving Frigate at a subpath (#12815)

Ensure axios.defaults.baseURL is set when accessing login form.

Drop `/api` prefix in login form's `axios.post` call, since `/api` is
part of the baseURL.

Redirect to subpath on succesful authentication.

Prepend subpath to default logout url.

Fixes #12814
This commit is contained in:
Soren L. Hansen 2024-08-09 06:26:26 -07:00 committed by GitHub
parent 6d9590b4ec
commit c84511de16
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 3 deletions

View File

@ -2,6 +2,7 @@
import * as React from "react";
import { baseUrl } from "../../api/baseUrl";
import { cn } from "@/lib/utils";
import { Input } from "@/components/ui/input";
import { Button } from "@/components/ui/button";
@ -43,7 +44,7 @@ export function UserAuthForm({ className, ...props }: UserAuthFormProps) {
setIsLoading(true);
try {
await axios.post(
"/api/login",
"/login",
{
user: values.user,
password: values.password,
@ -54,7 +55,7 @@ export function UserAuthForm({ className, ...props }: UserAuthFormProps) {
},
},
);
window.location.href = "/";
window.location.href = baseUrl;
} catch (error) {
if (axios.isAxiosError(error)) {
const err = error as AxiosError;

View File

@ -3,6 +3,7 @@ import {
TooltipContent,
TooltipTrigger,
} from "@/components/ui/tooltip";
import { baseUrl } from "../../api/baseUrl";
import { cn } from "@/lib/utils";
import { TooltipPortal } from "@radix-ui/react-tooltip";
import { isDesktop } from "react-device-detect";
@ -26,7 +27,7 @@ type AccountSettingsProps = {
export default function AccountSettings({ className }: AccountSettingsProps) {
const { data: profile } = useSWR("profile");
const { data: config } = useSWR("config");
const logoutUrl = config?.proxy?.logout_url || "/api/logout";
const logoutUrl = config?.proxy?.logout_url || `${baseUrl}api/logout`;
const Container = isDesktop ? DropdownMenu : Drawer;
const Trigger = isDesktop ? DropdownMenuTrigger : DrawerTrigger;

View File

@ -1,6 +1,7 @@
import React from "react";
import ReactDOM from "react-dom/client";
import LoginPage from "@/pages/LoginPage.tsx";
import "@/api";
import "./index.css";
ReactDOM.createRoot(document.getElementById("root")!).render(