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 +