Move api to v1 folder
This commit is contained in:
@@ -29,12 +29,12 @@ function Header({ user, loading }) {
|
||||
</Link>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/api/logout">Logout</a>
|
||||
<a href="/api/v1/logout">Logout</a>
|
||||
</li>
|
||||
</>
|
||||
) : (
|
||||
<li>
|
||||
<a href="/api/login">Login</a>
|
||||
<a href="/api/v1/login">Login</a>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
@@ -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;
|
||||
8
web/pages/api/v1/callback.js
Normal file
8
web/pages/api/v1/callback.js
Normal 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;
|
||||
@@ -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;
|
||||
8
web/pages/api/v1/login.js
Normal file
8
web/pages/api/v1/login.js
Normal 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;
|
||||
8
web/pages/api/v1/logout.js
Normal file
8
web/pages/api/v1/logout.js
Normal 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
8
web/pages/api/v1/me.js
Normal 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;
|
||||
@@ -20,7 +20,7 @@ function Home() {
|
||||
<i>Profile</i> and <i>Logout</i>
|
||||
</p>
|
||||
<p>
|
||||
<form method="POST" action="/api/bookmarks">
|
||||
<form method="POST" action="/api/v1/bookmarks">
|
||||
<label for="title">title: </label>
|
||||
<input type="text" name="title"/>
|
||||
<br />
|
||||
|
||||
Reference in New Issue
Block a user