From bcf6f763e80a3de8e41410e03dcaf57375e4c0b7 Mon Sep 17 00:00:00 2001 From: Hartaithan Date: Mon, 15 May 2023 13:27:24 +0900 Subject: [PATCH] move psn profile route and setup for /profile routes --- pages/_app.tsx | 2 +- pages/api/profile/index.ts | 24 +++++++++++++++++++ pages/api/{auth/profile.ts => profile/psn.ts} | 0 providers/ProfileProvider.tsx | 2 +- 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 pages/api/profile/index.ts rename pages/api/{auth/profile.ts => profile/psn.ts} (100%) diff --git a/pages/_app.tsx b/pages/_app.tsx index 9731add..c5f0113 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -79,7 +79,7 @@ const getPSNProfile = async ( } try { - const url = `${API_URL}/auth/profile`; + const url = `${API_URL}/profile/psn`; const response = await fetch(url, { method: "GET", credentials: "include", diff --git a/pages/api/profile/index.ts b/pages/api/profile/index.ts new file mode 100644 index 0000000..e04f77d --- /dev/null +++ b/pages/api/profile/index.ts @@ -0,0 +1,24 @@ +import { type NextApiHandler } from "next"; + +const getProfile: NextApiHandler = async (req, res) => { + return res.status(200).json({ message: "GET: Hello World!" }); +}; + +const updateProfile: NextApiHandler = async (req, res) => { + return res.status(200).json({ message: "PUT: Hello World!" }); +}; + +const handler: NextApiHandler = async (req, res) => { + const { method = "[Not Found]" } = req; + switch (method) { + case "GET": + return getProfile(req, res); + case "PUT": + return updateProfile(req, res); + default: + res.setHeader("Allow", ["GET", "PUT"]); + return res.status(405).end(`Method ${method} Not Allowed`); + } +}; + +export default handler; diff --git a/pages/api/auth/profile.ts b/pages/api/profile/psn.ts similarity index 100% rename from pages/api/auth/profile.ts rename to pages/api/profile/psn.ts diff --git a/providers/ProfileProvider.tsx b/providers/ProfileProvider.tsx index a7f7bfa..caf9daf 100644 --- a/providers/ProfileProvider.tsx +++ b/providers/ProfileProvider.tsx @@ -46,7 +46,7 @@ const ProfileProvider: FC = (props) => { const user = useUser(); const updatePSNProfile = (): void => { - API.get("/auth/profile") + API.get("/profile/psn") .then(({ data }) => { const psn_profile = data.profile; setProfiles((prev) => ({ ...prev, psn: psn_profile }));