From b922df3766ba7cf770b7bf92b88ffe1640f20d88 Mon Sep 17 00:00:00 2001 From: Late Night Defender Date: Mon, 3 Jun 2024 18:04:01 +0700 Subject: [PATCH] Use backend URL from .env --- src/components/DestinationInfoCard.vue | 4 +++- src/views/Favorite.vue | 2 +- src/views/Login.vue | 6 +++--- src/views/Register.vue | 2 +- src/views/Setting.vue | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/components/DestinationInfoCard.vue b/src/components/DestinationInfoCard.vue index 150fd4c..8fd6582 100644 --- a/src/components/DestinationInfoCard.vue +++ b/src/components/DestinationInfoCard.vue @@ -368,7 +368,9 @@ export default { if (currentUser) { console.log('Logged in. Proceed to add to favorites.'); - fetch("https://little-lines-backend.techtransthai.org/api/favorites/create", { + fetch(`${import.meta.env.VITE_BACKEND_URL}/api/favorites/create`, { + // fetch("https://little-lines-backend.techtransthai.org/api/favorites/create", { + method: "POST", headers: { 'Content-Type': 'application/json', diff --git a/src/views/Favorite.vue b/src/views/Favorite.vue index 23475f9..9ddbd0b 100644 --- a/src/views/Favorite.vue +++ b/src/views/Favorite.vue @@ -42,7 +42,7 @@ export default { const currentUser = JSON.parse(sessionStorage.getItem('current_user')); if (currentUser && currentUser.id) { - const response = await fetch(`https://little-lines-backend.techtransthai.org/api/favorites/${currentUser.id}`); + const response = await fetch(`${import.meta.env.VITE_BACKEND_URL}/api/favorites/${currentUser.id}`); if (!response.ok) { throw new Error('Failed to fetch favorites'); diff --git a/src/views/Login.vue b/src/views/Login.vue index 4e4a2a1..2a83e0c 100644 --- a/src/views/Login.vue +++ b/src/views/Login.vue @@ -98,7 +98,7 @@ export default { login() { if (this.input.email !== '' && this.input.password !== '') { console.log('Authenticated: Checking with Backend'); - fetch(`https://little-lines-backend.techtransthai.org/api/users/login`, { + fetch(`${import.meta.env.VITE_BACKEND_URL}/api/users/login`, { method: "POST", headers: { "Content-Type": "application/json", @@ -138,7 +138,7 @@ export default { client_id: import.meta.env.VITE_CLIENT_ID, scope: "email profile openid", - redirect_uri: "https://little-lines-backend.techtransthai.org/api/users/googleAuth/callback", + redirect_uri: `${import.meta.env.VITE_BACKEND_URL}/api/users/googleAuth/callback`, callback: response => { if (response.code) { this.sendCodeToBackend(response.code); @@ -153,7 +153,7 @@ export default { const headers = { Authorization: code }; - const response = await axios.post("https://little-lines-backend.techtransthai.org/api/users/googleAuth", null, { headers }); + const response = await axios.post(`${import.meta.env.VITE_BACKEND_URL}/api/users/googleAuth`, null, { headers }); const userDetails = response.data; console.log("User Details:", userDetails); this.userDetails = userDetails; diff --git a/src/views/Register.vue b/src/views/Register.vue index 8ce68be..944b976 100644 --- a/src/views/Register.vue +++ b/src/views/Register.vue @@ -108,7 +108,7 @@ import eyeNotLooking from '../../icons/Material/eye-not-looking.svg'; register() { if (this.input.username !== '' && ((this.input.password !='') && (this.input.password == this.input.passwordConfirm))) { console.log('Authenticated: Checking with Backend'); - fetch("https://little-lines-backend.techtransthai.org/api/users/create", { + fetch(`${import.meta.env.VITE_BACKEND_URL}/api/users/create`, { method: "POST", headers: { 'Content-Type': 'application/json', diff --git a/src/views/Setting.vue b/src/views/Setting.vue index f1693ba..d3bfe6a 100644 --- a/src/views/Setting.vue +++ b/src/views/Setting.vue @@ -97,7 +97,7 @@ const display_items = [ function logout() { if (sessionStorage.getItem('current_user')){ console.log('loging out...'); - fetch(`https://little-lines-backend.techtransthai.org/api/users/logout`, { + fetch(`${import.meta.env.VITE_BACKEND_URL}/api/users/logout`, { method: "GET" }).then(()=>{ console.log('loged out');