Skip to content

Commit

Permalink
Fix auth when serving Frigate at a subpath (#12815)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sorenisanerd authored and NickM-27 committed Aug 30, 2024
1 parent 87b69c3 commit b01ce31
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions web/src/components/auth/AuthForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion web/src/components/menu/AccountSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions web/src/login.tsx
Original file line number Diff line number Diff line change
@@ -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(
Expand Down

0 comments on commit b01ce31

Please sign in to comment.