Skip to content

Commit

Permalink
fix: base url issue
Browse files Browse the repository at this point in the history
  • Loading branch information
csuvajit committed Nov 9, 2024
1 parent 020e879 commit 43b1807
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 37 deletions.
15 changes: 9 additions & 6 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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('/');
Expand Down
10 changes: 5 additions & 5 deletions app/rosters/components/RostersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => (
<Stack
Expand Down Expand Up @@ -368,14 +368,14 @@ export const RostersPage = (props: {
)}
</Box>

<Stack spacing={1} direction="row-reverse">
{/* <Stack spacing={1} direction="row-reverse">
<Button variant="outlined" sx={{ height: 30 }}>
Edit
</Button>
<Button color="error" variant="outlined" sx={{ height: 30 }}>
Delete
</Button>
</Stack>
</Stack> */}
</Stack>

<Table aria-label="table" sx={{ mb: 3 }}>
Expand Down
49 changes: 29 additions & 20 deletions hooks/useAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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}`
Expand All @@ -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: {
Expand Down
8 changes: 2 additions & 6 deletions lib/constants.ts
Original file line number Diff line number Diff line change
@@ -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('|')
Expand Down

0 comments on commit 43b1807

Please sign in to comment.