From 2e57e2e5a0e953a44bb756d3fab8edc1050606de Mon Sep 17 00:00:00 2001 From: Matthias-VE Date: Mon, 20 May 2024 10:45:34 +0200 Subject: [PATCH] edit hard coded urls --- frontend/src/components/layout/nav/AuthNav.tsx | 3 ++- frontend/src/components/layout/nav/UnauthNav.tsx | 3 ++- frontend/src/pages/index/landing/LandingPage.tsx | 3 ++- frontend/src/util/backendServer.ts | 3 +++ 4 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 frontend/src/util/backendServer.ts diff --git a/frontend/src/components/layout/nav/AuthNav.tsx b/frontend/src/components/layout/nav/AuthNav.tsx index feaae7bc..f44aba9e 100644 --- a/frontend/src/components/layout/nav/AuthNav.tsx +++ b/frontend/src/components/layout/nav/AuthNav.tsx @@ -11,6 +11,7 @@ import useAuth from "../../../hooks/useAuth" import createCourseModal from "../../../pages/index/components/CreateCourseModal" import useIsTeacher from "../../../hooks/useIsTeacher" +import {BACKEND_SERVER} from "../../../util/backendServer"; const AuthNav = () => { @@ -66,7 +67,7 @@ const AuthNav = () => { break case "logout": auth.logout() - window.location.replace("http://localhost:3000/web/auth/signout") + window.location.replace(BACKEND_SERVER + "/web/auth/signout") break case Themes.DARK: case Themes.LIGHT: diff --git a/frontend/src/components/layout/nav/UnauthNav.tsx b/frontend/src/components/layout/nav/UnauthNav.tsx index 761731ce..7066c747 100644 --- a/frontend/src/components/layout/nav/UnauthNav.tsx +++ b/frontend/src/components/layout/nav/UnauthNav.tsx @@ -2,6 +2,7 @@ import { useTranslation } from "react-i18next"; import { Button } from "antd"; import useAuth from "../../../hooks/useAuth"; import {useNavigate} from "react-router-dom"; +import {BACKEND_SERVER} from "../../../util/backendServer"; const UnauthNav = () => { const { t } = useTranslation(); @@ -10,7 +11,7 @@ const UnauthNav = () => { const handleLogin = async () => { try { await auth.login() - window.location.replace("http://localhost:3000/web/auth/signin") + window.location.replace(BACKEND_SERVER + "/web/auth/signin") } catch (error) { console.error(error) } diff --git a/frontend/src/pages/index/landing/LandingPage.tsx b/frontend/src/pages/index/landing/LandingPage.tsx index bb0e6e19..d210000a 100644 --- a/frontend/src/pages/index/landing/LandingPage.tsx +++ b/frontend/src/pages/index/landing/LandingPage.tsx @@ -13,6 +13,7 @@ import { useTranslation } from "react-i18next" import { motion } from "framer-motion" import useAuth from "../../../hooks/useAuth"; import {useNavigate} from "react-router-dom"; +import {BACKEND_SERVER} from "../../../util/backendServer"; const defaultTransition = { duration: 0.5, ease: [0.44, 0, 0.56, 1], type: "tween" } @@ -27,7 +28,7 @@ const LandingPage: FC = () => { const handleLogin = async () => { try { await auth.login() - window.location.replace("http://localhost:3000/web/auth/signin") + window.location.replace(BACKEND_SERVER + "/web/auth/signin") } catch (error) { console.error(error) } diff --git a/frontend/src/util/backendServer.ts b/frontend/src/util/backendServer.ts new file mode 100644 index 00000000..ec14c445 --- /dev/null +++ b/frontend/src/util/backendServer.ts @@ -0,0 +1,3 @@ + +export const BACKEND_SERVER = window.location.origin.includes("localhost") ? "http://localhost:3000" : window.location.origin +