From 43b18071beb8f5c0d992ccc2fc17f0f01b113fcb Mon Sep 17 00:00:00 2001 From: suvajit Date: Sat, 9 Nov 2024 20:29:23 +0530 Subject: [PATCH] fix: base url issue --- app/layout.tsx | 15 ++++---- app/rosters/components/RostersPage.tsx | 10 +++--- hooks/useAPI.ts | 49 +++++++++++++++----------- lib/constants.ts | 8 ++--- 4 files changed, 45 insertions(+), 37 deletions(-) diff --git a/app/layout.tsx b/app/layout.tsx index b1a24e4..262c800 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -45,13 +45,16 @@ const validateAuth = async () => { const isAuthenticatedPath = authenticatedPathRegex.test(pathname); if (!isAuthenticatedPath) return null; - const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/auth/status`, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - Authorization: `Bearer ${accessToken}` + const res = await fetch( + `${process.env.NEXT_PUBLIC_BACKEND_URL}/auth/status`, + { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${accessToken}` + } } - }); + ); if (res.status === 401 || res.status === 403) { return redirect('/'); diff --git a/app/rosters/components/RostersPage.tsx b/app/rosters/components/RostersPage.tsx index a2465e3..86d6e44 100644 --- a/app/rosters/components/RostersPage.tsx +++ b/app/rosters/components/RostersPage.tsx @@ -305,15 +305,15 @@ export const RostersPage = (props: { }, { name: 'Minimum TownHall', - value: `${roster.minTownHall || 0}` + value: `${roster.minTownHall || '-'}` }, { name: 'Maximum TownHall', - value: `${roster.maxTownHall || 0}` + value: `${roster.maxTownHall || '-'}` }, { name: 'Minimum Hero Level', - value: `${roster.minHeroLevels || 0}` + value: `${roster.minHeroLevels || '-'}` } ].map((item, idx) => ( - + {/* - + */} diff --git a/hooks/useAPI.ts b/hooks/useAPI.ts index 7028780..41b3ac9 100644 --- a/hooks/useAPI.ts +++ b/hooks/useAPI.ts @@ -4,13 +4,16 @@ import { GuildClansAggregated } from './types'; export const useAPI = () => { const login = async (email: string, password: string) => { - const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/auth/login`, { - method: 'POST', - body: JSON.stringify({ email, password }), - headers: { - 'Content-Type': 'application/json' + const res = await fetch( + `${process.env.NEXT_PUBLIC_BACKEND_URL}/auth/login`, + { + method: 'POST', + body: JSON.stringify({ email, password }), + headers: { + 'Content-Type': 'application/json' + } } - }); + ); const data = await res.json(); if (!res.ok) { @@ -23,13 +26,16 @@ export const useAPI = () => { }; const signup = async (email: string, password: string, fullName: string) => { - const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/auth/signup`, { - method: 'POST', - body: JSON.stringify({ email, password, fullName }), - headers: { - 'Content-Type': 'application/json' + const res = await fetch( + `${process.env.NEXT_PUBLIC_BACKEND_URL}/auth/signup`, + { + method: 'POST', + body: JSON.stringify({ email, password, fullName }), + headers: { + 'Content-Type': 'application/json' + } } - }); + ); const data = await res.json(); if (!res.ok) { @@ -43,13 +49,16 @@ export const useAPI = () => { const testToken = async () => { const accessToken = getCookie(authCookieKey); - const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/auth/signup`, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - Authorization: `Bearer ${accessToken}` + const res = await fetch( + `${process.env.NEXT_PUBLIC_BACKEND_URL}/auth/signup`, + { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${accessToken}` + } } - }); + ); const data = await res.json(); if (!res.ok) { @@ -61,7 +70,7 @@ export const useAPI = () => { const uploadFile = async (formData: FormData) => { const accessToken = getCookie(authCookieKey); - const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/upload`, { + const res = await fetch(`${process.env.NEXT_PUBLIC_BACKEND_URL}/upload`, { method: 'POST', headers: { Authorization: `Bearer ${accessToken}` @@ -82,7 +91,7 @@ export const useAPI = () => { const getClans = async ({ guildId }: { guildId: string }) => { const accessToken = getCookie(authCookieKey); const res = await fetch( - `${process.env.NEXT_PUBLIC_API_URL}/guilds/${guildId}`, + `${process.env.NEXT_PUBLIC_BACKEND_URL}/guilds/${guildId}`, { method: 'GET', headers: { diff --git a/lib/constants.ts b/lib/constants.ts index 4288070..825355a 100644 --- a/lib/constants.ts +++ b/lib/constants.ts @@ -1,12 +1,8 @@ export const authCookieKey = 'x-token'; -export const authenticatedPaths = ['/embeds', '/reminders', '/rosters']; +export const authenticatedPaths = ['/embeds', '/reminders']; -export const authenticatedPathsRegex = [ - /^\/embeds/, - /^\/reminders/, - /^\/rosters\/?/ -]; +export const authenticatedPathsRegex = [/^\/embeds/, /^\/reminders/]; export const authenticatedPathRegex = new RegExp( authenticatedPathsRegex.map((route) => route.source).join('|')