From afbd654c37b3328220ea56cd8136faaede0b8639 Mon Sep 17 00:00:00 2001 From: Sirin Puenggun Date: Wed, 22 Nov 2023 16:10:32 +0700 Subject: [PATCH 1/5] Update LoginPage.jsx --- frontend/src/components/authentication/LoginPage.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/authentication/LoginPage.jsx b/frontend/src/components/authentication/LoginPage.jsx index 93f8f0b..0075cd7 100644 --- a/frontend/src/components/authentication/LoginPage.jsx +++ b/frontend/src/components/authentication/LoginPage.jsx @@ -4,7 +4,7 @@ import { useGoogleLogin } from "@react-oauth/google"; import { useCallback } from "react"; import Particles from "react-tsparticles"; import { loadFull } from "tsparticles"; -import refreshAccessToken from "./refreshAcesstoken"; +import refreshAccessToken from "./refreshAcessToken"; import axiosapi from "../../api/AuthenticationApi"; import { useAuth } from "../../hooks/authentication/IsAuthenticated"; import { FcGoogle } from "react-icons/fc"; From 58bfb0edb6174f5f5fa2691b9753fa31a1fb7450 Mon Sep 17 00:00:00 2001 From: Sirin Puenggun Date: Wed, 22 Nov 2023 20:29:04 +0700 Subject: [PATCH 2/5] Update dashboard.jsx --- frontend/src/components/dashboard/dashboard.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/dashboard/dashboard.jsx b/frontend/src/components/dashboard/dashboard.jsx index 5a2b91c..b1da562 100644 --- a/frontend/src/components/dashboard/dashboard.jsx +++ b/frontend/src/components/dashboard/dashboard.jsx @@ -10,7 +10,7 @@ import { Title, Legend, } from "@tremor/react"; -import KpiCard from "./kpiCard"; +import KpiCard from "./KpiCard"; import { BarChartGraph } from "./Barchart"; import DonutChartGraph from "./DonutChart"; import { AreaChartGraph } from "./Areachart"; From 6ac8c65de70bc3ea24a152e7f8cf561c5762f10f Mon Sep 17 00:00:00 2001 From: sosokker Date: Wed, 22 Nov 2023 21:01:43 +0700 Subject: [PATCH 3/5] Set baseURL variable --- frontend/src/App.jsx | 4 +++- frontend/src/api/AuthenticationApi.jsx | 6 ++++-- frontend/src/api/AxiosConfig.jsx | 4 +++- frontend/src/api/TaskApi.jsx | 2 +- frontend/src/api/UserProfileApi.jsx | 6 ++++-- .../src/components/authentication/refreshAcessToken.jsx | 4 +++- 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 83ebef6..89166b6 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -16,6 +16,8 @@ import Dashboard from "./components/dashboard/dashboard"; import { useAuth } from "./hooks/AuthHooks"; +const baseURL = import.meta.env.VITE_BASE_URL; + const App = () => { const { isAuthenticated, setIsAuthenticated } = useAuth(); @@ -27,7 +29,7 @@ const App = () => { }; await axios - .post("http://127.0.0.1:8000/api/auth/status/", data, { + .post(`${baseURL}auth/status/`, data, { headers: { Authorization: "Bearer " + localStorage.getItem("access_token"), }, diff --git a/frontend/src/api/AuthenticationApi.jsx b/frontend/src/api/AuthenticationApi.jsx index 7f88744..bca81d5 100644 --- a/frontend/src/api/AuthenticationApi.jsx +++ b/frontend/src/api/AuthenticationApi.jsx @@ -1,6 +1,8 @@ import axios from "axios"; import axiosInstance from "./AxiosConfig"; +const baseURL = import.meta.env.VITE_BASE_URL; + // Function for user login const apiUserLogin = (data) => { return axiosInstance @@ -26,7 +28,7 @@ const apiUserLogout = () => { // Function for Google login const googleLogin = async (token) => { axios.defaults.withCredentials = true; - let res = await axios.post("http://localhost:8000/api/auth/google/", { + let res = await axios.post(`${baseURL}auth/google/`, { code: token, }); // console.log('service google login res: ', res); @@ -49,7 +51,7 @@ const getGreeting = () => { const createUser = async (formData) => { try { axios.defaults.withCredentials = true; - const response = axios.post("http://localhost:8000/api/user/create/", formData); + const response = axios.post(`${baseURL}user/create/`, formData); // const response = await axiosInstance.post('/user/create/', formData); return response.data; } catch (e) { diff --git a/frontend/src/api/AxiosConfig.jsx b/frontend/src/api/AxiosConfig.jsx index 7b701bd..b037386 100644 --- a/frontend/src/api/AxiosConfig.jsx +++ b/frontend/src/api/AxiosConfig.jsx @@ -1,8 +1,10 @@ import axios from "axios"; import { redirect } from "react-router-dom"; +const baseURL = import.meta.env.VITE_BASE_URL; + const axiosInstance = axios.create({ - baseURL: "http://127.0.0.1:8000/api/", + baseURL: baseURL, timeout: 5000, headers: { Authorization: "Bearer " + localStorage.getItem("access_token"), diff --git a/frontend/src/api/TaskApi.jsx b/frontend/src/api/TaskApi.jsx index 45737f9..daad9c3 100644 --- a/frontend/src/api/TaskApi.jsx +++ b/frontend/src/api/TaskApi.jsx @@ -1,6 +1,6 @@ import axiosInstance from "src/api/AxiosConfig"; -const baseURL = ""; +const baseURL = import.meta.env.VITE_BASE_URL; export const createTask = (endpoint, data) => { return axiosInstance diff --git a/frontend/src/api/UserProfileApi.jsx b/frontend/src/api/UserProfileApi.jsx index e7a1b17..6dfc050 100644 --- a/frontend/src/api/UserProfileApi.jsx +++ b/frontend/src/api/UserProfileApi.jsx @@ -1,8 +1,10 @@ import axios from "axios"; -const ApiUpdateUserProfile = async formData => { +const baseURL = import.meta.env.VITE_BASE_URL; + +const ApiUpdateUserProfile = async (formData) => { try { - const response = await axios.post("http://127.0.1:8000/api/user/update/", formData, { + const response = await axios.post(`${baseURL}user/update/`, formData, { headers: { Authorization: "Bearer " + localStorage.getItem("access_token"), "Content-Type": "multipart/form-data", diff --git a/frontend/src/components/authentication/refreshAcessToken.jsx b/frontend/src/components/authentication/refreshAcessToken.jsx index 11a74fa..e07395b 100644 --- a/frontend/src/components/authentication/refreshAcessToken.jsx +++ b/frontend/src/components/authentication/refreshAcessToken.jsx @@ -1,5 +1,7 @@ import axios from "axios"; +const baseURL = import.meta.env.VITE_BASE_URL; + async function refreshAccessToken() { const refresh_token = localStorage.getItem("refresh_token"); const access_token = localStorage.getItem("access_token"); @@ -12,7 +14,7 @@ async function refreshAccessToken() { return false; } - const refreshUrl = "http://127.0.0.1:8000/api/token/refresh/"; + const refreshUrl = `${baseURL}token/refresh/`; try { const response = await axios.post(refreshUrl, { refresh: refresh_token }); From 84bd04126e7f081c265bab17881db68058e0eb8c Mon Sep 17 00:00:00 2001 From: sosokker Date: Wed, 22 Nov 2023 22:47:16 +0700 Subject: [PATCH 4/5] Update vite.config.js --- frontend/vite.config.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/vite.config.js b/frontend/vite.config.js index 3dcabd8..ee38796 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -1,7 +1,6 @@ import { defineConfig } from "vite"; import react from "@vitejs/plugin-react"; -// https://vitejs.dev/config/ export default defineConfig({ plugins: [react()], resolve: { @@ -9,4 +8,7 @@ export default defineConfig({ src: "/src", }, }, + define: { + __APP_ENV__: import.meta.env.VITE_VERCEL_ENV, + }, }); From 8574635076aa588bc8f8c10809530b25e4c22944 Mon Sep 17 00:00:00 2001 From: sosokker Date: Wed, 22 Nov 2023 22:51:42 +0700 Subject: [PATCH 5/5] Update vercel include path --- frontend/.eslintrc.cjs | 25 +++++++++++-------------- frontend/vite.config.js | 2 +- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/frontend/.eslintrc.cjs b/frontend/.eslintrc.cjs index 4dcb439..1a8aa39 100644 --- a/frontend/.eslintrc.cjs +++ b/frontend/.eslintrc.cjs @@ -1,20 +1,17 @@ module.exports = { root: true, - env: { browser: true, es2020: true }, + env: { browser: true, es2020: true, node: true }, extends: [ - 'eslint:recommended', - 'plugin:react/recommended', - 'plugin:react/jsx-runtime', - 'plugin:react-hooks/recommended', + "eslint:recommended", + "plugin:react/recommended", + "plugin:react/jsx-runtime", + "plugin:react-hooks/recommended", ], - ignorePatterns: ['dist', '.eslintrc.cjs'], - parserOptions: { ecmaVersion: 'latest', sourceType: 'module' }, - settings: { react: { version: '18.2' } }, - plugins: ['react-refresh'], + ignorePatterns: ["dist", ".eslintrc.cjs"], + parserOptions: { ecmaVersion: "latest", sourceType: "module" }, + settings: { react: { version: "18.2" } }, + plugins: ["react-refresh"], rules: { - 'react-refresh/only-export-components': [ - 'warn', - { allowConstantExport: true }, - ], + "react-refresh/only-export-components": ["warn", { allowConstantExport: true }], }, -} +}; diff --git a/frontend/vite.config.js b/frontend/vite.config.js index ee38796..536af4a 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -9,6 +9,6 @@ export default defineConfig({ }, }, define: { - __APP_ENV__: import.meta.env.VITE_VERCEL_ENV, + __APP_ENV__: process.env.VITE_VERCEL_ENV, }, });