From 2fa58305cb5b16341753e42a9b2662050365a6cf Mon Sep 17 00:00:00 2001
From: Ben Ramey
Date: Mon, 27 Jun 2022 09:08:26 -0500
Subject: [PATCH] Move api to v1 folder
---
web/components/header.js | 4 ++--
web/lib/auth0.js | 2 +-
web/lib/user.js | 4 ++--
web/pages/advanced/ssr-profile.js | 2 +-
web/pages/api/callback.js | 6 ------
web/pages/api/login.js | 6 ------
web/pages/api/logout.js | 6 ------
web/pages/api/me.js | 6 ------
web/pages/api/{ => v1}/bookmarks.js | 4 ++--
web/pages/api/v1/callback.js | 8 ++++++++
web/pages/api/{ => v1}/hello.js | 4 ++--
web/pages/api/v1/login.js | 8 ++++++++
web/pages/api/v1/logout.js | 8 ++++++++
web/pages/api/v1/me.js | 8 ++++++++
web/pages/index.js | 2 +-
15 files changed, 43 insertions(+), 35 deletions(-)
delete mode 100644 web/pages/api/callback.js
delete mode 100644 web/pages/api/login.js
delete mode 100644 web/pages/api/logout.js
delete mode 100644 web/pages/api/me.js
rename web/pages/api/{ => v1}/bookmarks.js (94%)
create mode 100644 web/pages/api/v1/callback.js
rename web/pages/api/{ => v1}/hello.js (86%)
create mode 100644 web/pages/api/v1/login.js
create mode 100644 web/pages/api/v1/logout.js
create mode 100644 web/pages/api/v1/me.js
diff --git a/web/components/header.js b/web/components/header.js
index b83e585..6951455 100644
--- a/web/components/header.js
+++ b/web/components/header.js
@@ -29,12 +29,12 @@ function Header({ user, loading }) {
- Logout
+ Logout
>
) : (
- Login
+ Login
))}
diff --git a/web/lib/auth0.js b/web/lib/auth0.js
index cd241d5..ed4fda6 100644
--- a/web/lib/auth0.js
+++ b/web/lib/auth0.js
@@ -9,7 +9,7 @@ export default initAuth0({
routes: {
callback:
process.env.NEXT_PUBLIC_REDIRECT_URI ||
- "http://localhost:3000/api/callback",
+ "http://localhost:3000/api/v1/callback",
postLogoutRedirect:
process.env.NEXT_PUBLIC_POST_LOGOUT_REDIRECT_URI ||
"http://localhost:3000",
diff --git a/web/lib/user.js b/web/lib/user.js
index 3971560..4a3243f 100644
--- a/web/lib/user.js
+++ b/web/lib/user.js
@@ -6,7 +6,7 @@ export async function fetchUser(cookie = "") {
}
const res = await fetch(
- "/api/me",
+ "/api/v1/me",
cookie
? {
headers: {
@@ -53,7 +53,7 @@ export function useFetchUser({ required } = {}) {
if (isMounted) {
// When the user is not logged in but login is required
if (required && !user) {
- window.location.href = "/api/login";
+ window.location.href = "/api/v1/login";
return;
}
setUser(user);
diff --git a/web/pages/advanced/ssr-profile.js b/web/pages/advanced/ssr-profile.js
index 5c3b651..4405b9e 100644
--- a/web/pages/advanced/ssr-profile.js
+++ b/web/pages/advanced/ssr-profile.js
@@ -25,7 +25,7 @@ export async function getServerSideProps({ req, res }) {
if (!session || !session.user) {
res.writeHead(302, {
- Location: "/api/login",
+ Location: "/api/v1/login",
});
res.end();
return;
diff --git a/web/pages/api/callback.js b/web/pages/api/callback.js
deleted file mode 100644
index dbeb16d..0000000
--- a/web/pages/api/callback.js
+++ /dev/null
@@ -1,6 +0,0 @@
-import auth0 from "../../lib/auth0";
-import { withErrorHandling } from "../../lib/apiHelpers";
-
-export default callback = withErrorHandling(async (req, res) => {
- await auth0.handleCallback(req, res);
-});
diff --git a/web/pages/api/login.js b/web/pages/api/login.js
deleted file mode 100644
index 407753c..0000000
--- a/web/pages/api/login.js
+++ /dev/null
@@ -1,6 +0,0 @@
-import auth0 from "../../lib/auth0";
-import { withErrorHandling } from "../../lib/apiHelpers";
-
-export default login = withErrorHandling(async (req, res) => {
- await auth0.handleLogin(req, res);
-});
diff --git a/web/pages/api/logout.js b/web/pages/api/logout.js
deleted file mode 100644
index 2e2e593..0000000
--- a/web/pages/api/logout.js
+++ /dev/null
@@ -1,6 +0,0 @@
-import auth0 from "../../lib/auth0";
-import { withErrorHandling } from "../../lib/apiHelpers";
-
-export default logout = withErrorHandling(async (req, res) => {
- await auth0.handleLogout(req, res);
-});
diff --git a/web/pages/api/me.js b/web/pages/api/me.js
deleted file mode 100644
index a87c849..0000000
--- a/web/pages/api/me.js
+++ /dev/null
@@ -1,6 +0,0 @@
-import auth0 from "../../lib/auth0";
-import { withErrorHandling } from "../../lib/apiHelpers";
-
-export default me = withErrorHandling(async (req, res) => {
- await auth0.handleProfile(req, res);
-});
diff --git a/web/pages/api/bookmarks.js b/web/pages/api/v1/bookmarks.js
similarity index 94%
rename from web/pages/api/bookmarks.js
rename to web/pages/api/v1/bookmarks.js
index 8d995d7..9d5b714 100644
--- a/web/pages/api/bookmarks.js
+++ b/web/pages/api/v1/bookmarks.js
@@ -1,7 +1,7 @@
-import db from "../../lib/db";
+import db from "../../../lib/db";
import Ajv from "ajv";
import addFormats from "ajv-formats";
-import { withErrorHandling } from "../../lib/apiHelpers";
+import { withErrorHandling } from "../../../lib/apiHelpers";
const handler = withErrorHandling(async (req, res) => {
const { method } = req;
diff --git a/web/pages/api/v1/callback.js b/web/pages/api/v1/callback.js
new file mode 100644
index 0000000..1f86452
--- /dev/null
+++ b/web/pages/api/v1/callback.js
@@ -0,0 +1,8 @@
+import auth0 from "../../../lib/auth0";
+import { withErrorHandling } from "../../../lib/apiHelpers";
+
+const callback = withErrorHandling(async (req, res) => {
+ await auth0.handleCallback(req, res);
+});
+
+export default callback;
diff --git a/web/pages/api/hello.js b/web/pages/api/v1/hello.js
similarity index 86%
rename from web/pages/api/hello.js
rename to web/pages/api/v1/hello.js
index f18ae0f..4ddfb1f 100644
--- a/web/pages/api/hello.js
+++ b/web/pages/api/v1/hello.js
@@ -1,5 +1,5 @@
-import db from "../../lib/db";
-import { withErrorHandling } from "../../lib/apiHelpers";
+import db from "../../../lib/db";
+import { withErrorHandling } from "../../../lib/apiHelpers";
const handler = withErrorHandling(async (req, res) => {
const { method } = req;
diff --git a/web/pages/api/v1/login.js b/web/pages/api/v1/login.js
new file mode 100644
index 0000000..c9334f6
--- /dev/null
+++ b/web/pages/api/v1/login.js
@@ -0,0 +1,8 @@
+import auth0 from "../../../lib/auth0";
+import { withErrorHandling } from "../../../lib/apiHelpers";
+
+const login = withErrorHandling(async (req, res) => {
+ await auth0.handleLogin(req, res);
+});
+
+export default login;
diff --git a/web/pages/api/v1/logout.js b/web/pages/api/v1/logout.js
new file mode 100644
index 0000000..b788412
--- /dev/null
+++ b/web/pages/api/v1/logout.js
@@ -0,0 +1,8 @@
+import auth0 from "../../../lib/auth0";
+import { withErrorHandling } from "../../../lib/apiHelpers";
+
+const logout = withErrorHandling(async (req, res) => {
+ await auth0.handleLogout(req, res);
+});
+
+export default logout;
diff --git a/web/pages/api/v1/me.js b/web/pages/api/v1/me.js
new file mode 100644
index 0000000..d3ad9f1
--- /dev/null
+++ b/web/pages/api/v1/me.js
@@ -0,0 +1,8 @@
+import auth0 from "../../../lib/auth0";
+import { withErrorHandling } from "../../../lib/apiHelpers";
+
+const me = withErrorHandling(async (req, res) => {
+ await auth0.handleProfile(req, res);
+});
+
+export default me;
diff --git a/web/pages/index.js b/web/pages/index.js
index 60f1e97..806760b 100644
--- a/web/pages/index.js
+++ b/web/pages/index.js
@@ -20,7 +20,7 @@ function Home() {
Profile and Logout
-