Move api to v1 folder

This commit is contained in:
2022-06-27 09:08:26 -05:00
parent 6fe79a1892
commit 2fa58305cb
15 changed files with 43 additions and 35 deletions

View File

@@ -29,12 +29,12 @@ function Header({ user, loading }) {
</Link> </Link>
</li> </li>
<li> <li>
<a href="/api/logout">Logout</a> <a href="/api/v1/logout">Logout</a>
</li> </li>
</> </>
) : ( ) : (
<li> <li>
<a href="/api/login">Login</a> <a href="/api/v1/login">Login</a>
</li> </li>
))} ))}
</ul> </ul>

View File

@@ -9,7 +9,7 @@ export default initAuth0({
routes: { routes: {
callback: callback:
process.env.NEXT_PUBLIC_REDIRECT_URI || process.env.NEXT_PUBLIC_REDIRECT_URI ||
"http://localhost:3000/api/callback", "http://localhost:3000/api/v1/callback",
postLogoutRedirect: postLogoutRedirect:
process.env.NEXT_PUBLIC_POST_LOGOUT_REDIRECT_URI || process.env.NEXT_PUBLIC_POST_LOGOUT_REDIRECT_URI ||
"http://localhost:3000", "http://localhost:3000",

View File

@@ -6,7 +6,7 @@ export async function fetchUser(cookie = "") {
} }
const res = await fetch( const res = await fetch(
"/api/me", "/api/v1/me",
cookie cookie
? { ? {
headers: { headers: {
@@ -53,7 +53,7 @@ export function useFetchUser({ required } = {}) {
if (isMounted) { if (isMounted) {
// When the user is not logged in but login is required // When the user is not logged in but login is required
if (required && !user) { if (required && !user) {
window.location.href = "/api/login"; window.location.href = "/api/v1/login";
return; return;
} }
setUser(user); setUser(user);

View File

@@ -25,7 +25,7 @@ export async function getServerSideProps({ req, res }) {
if (!session || !session.user) { if (!session || !session.user) {
res.writeHead(302, { res.writeHead(302, {
Location: "/api/login", Location: "/api/v1/login",
}); });
res.end(); res.end();
return; return;

View File

@@ -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);
});

View File

@@ -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);
});

View File

@@ -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);
});

View File

@@ -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);
});

View File

@@ -1,7 +1,7 @@
import db from "../../lib/db"; import db from "../../../lib/db";
import Ajv from "ajv"; import Ajv from "ajv";
import addFormats from "ajv-formats"; import addFormats from "ajv-formats";
import { withErrorHandling } from "../../lib/apiHelpers"; import { withErrorHandling } from "../../../lib/apiHelpers";
const handler = withErrorHandling(async (req, res) => { const handler = withErrorHandling(async (req, res) => {
const { method } = req; const { method } = req;

View File

@@ -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;

View File

@@ -1,5 +1,5 @@
import db from "../../lib/db"; import db from "../../../lib/db";
import { withErrorHandling } from "../../lib/apiHelpers"; import { withErrorHandling } from "../../../lib/apiHelpers";
const handler = withErrorHandling(async (req, res) => { const handler = withErrorHandling(async (req, res) => {
const { method } = req; const { method } = req;

View File

@@ -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;

View File

@@ -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;

8
web/pages/api/v1/me.js Normal file
View File

@@ -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;

View File

@@ -20,7 +20,7 @@ function Home() {
<i>Profile</i> and <i>Logout</i> <i>Profile</i> and <i>Logout</i>
</p> </p>
<p> <p>
<form method="POST" action="/api/bookmarks"> <form method="POST" action="/api/v1/bookmarks">
<label for="title">title: </label> <label for="title">title: </label>
<input type="text" name="title"/> <input type="text" name="title"/>
<br /> <br />