Skip to content

Commit

Permalink
use axios for client side requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Hartaithan committed Mar 26, 2023
1 parent 3124edf commit df47ae8
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 18 deletions.
14 changes: 14 additions & 0 deletions api/API.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import axios from "axios";

const config = {
baseURL: process.env.NEXT_PUBLIC_API_URL,
headers: {
"X-Requested-With": "XMLHttpRequest",
Accept: "application/json",
"Content-Type": "application/json",
},
};

const API = axios.create(config);

export default API;
91 changes: 91 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@types/node": "18.15.3",
"@types/react": "18.0.28",
"@types/react-dom": "18.0.11",
"axios": "^1.3.4",
"cookies-next": "^2.1.1",
"eslint-config-next": "13.2.4",
"next": "13.2.4",
Expand Down
10 changes: 2 additions & 8 deletions pages/signIn.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import API from "@/api/API";
import { type IPage } from "@/models/AppModel";
import {
Button,
Expand Down Expand Up @@ -44,14 +45,7 @@ const SignInPage: IPage = () => {
console.error("API_URL not found");
return;
}
fetch(`${API_URL}/signIn`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(values),
})
.then(async (response) => await response.json())
API.post("/signIn", JSON.stringify(values))
.then(() => {
reload();
})
Expand Down
14 changes: 4 additions & 10 deletions pages/signUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Title,
} from "@mantine/core";
import { useForm, isEmail, hasLength } from "@mantine/form";
import API from "@/api/API";

const API_URL = process.env.NEXT_PUBLIC_API_URL;

Expand Down Expand Up @@ -47,16 +48,9 @@ const SignUpPage: IPage = () => {
console.error("API_URL not found");
return;
}
fetch(`${API_URL}/signUp`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(values),
})
.then(async (response) => await response.json())
.then(({ user }) => {
setUser(user);
API.post("/signUp", JSON.stringify(values))
.then(({ data }) => {
setUser(data.user);
})
.catch((error) => {
// TODO: add error notifications
Expand Down

1 comment on commit df47ae8

@vercel
Copy link

@vercel vercel bot commented on df47ae8 Mar 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

trophy-hunt – ./

trophy-hunt-git-main-hartaithan.vercel.app
trophy-hunt-hartaithan.vercel.app
trophy-hunt.vercel.app

Please sign in to comment.