Spaces:
Running
Running
add middleware
Browse files- app/api/auth/route.ts +4 -2
- app/auth/page.tsx +9 -1
- components/editor/save-button/index.tsx +2 -2
- middleware.ts +12 -0
app/api/auth/route.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
| 1 |
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
|
| 3 |
export async function GET(req: NextRequest) {
|
| 4 |
-
const host =
|
| 5 |
-
|
|
|
|
|
|
|
| 6 |
|
| 7 |
const redirect_uri =
|
| 8 |
`${host.includes("localhost") ? "http://" : "https://"}` +
|
|
|
|
| 1 |
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
|
| 3 |
export async function GET(req: NextRequest) {
|
| 4 |
+
const host =
|
| 5 |
+
req.headers.get("x-current-host") ??
|
| 6 |
+
req.headers.get("host") ??
|
| 7 |
+
"localhost:3000";
|
| 8 |
|
| 9 |
const redirect_uri =
|
| 10 |
`${host.includes("localhost") ? "http://" : "https://"}` +
|
app/auth/page.tsx
CHANGED
|
@@ -1,10 +1,18 @@
|
|
| 1 |
import { redirect } from "next/navigation";
|
| 2 |
import { Metadata } from "next";
|
|
|
|
|
|
|
| 3 |
import { apiServer } from "@/lib/api";
|
| 4 |
|
| 5 |
async function getLoginUrl() {
|
|
|
|
|
|
|
| 6 |
try {
|
| 7 |
-
const res = await apiServer.get("/auth"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
return res.data;
|
| 9 |
} catch (error) {
|
| 10 |
return error;
|
|
|
|
| 1 |
import { redirect } from "next/navigation";
|
| 2 |
import { Metadata } from "next";
|
| 3 |
+
import { headers } from "next/headers";
|
| 4 |
+
|
| 5 |
import { apiServer } from "@/lib/api";
|
| 6 |
|
| 7 |
async function getLoginUrl() {
|
| 8 |
+
const headersList = await headers();
|
| 9 |
+
const pathname = headersList.get("x-current-host") || "/";
|
| 10 |
try {
|
| 11 |
+
const res = await apiServer.get("/auth", {
|
| 12 |
+
headers: {
|
| 13 |
+
"x-current-host": pathname,
|
| 14 |
+
},
|
| 15 |
+
});
|
| 16 |
return res.data;
|
| 17 |
} catch (error) {
|
| 18 |
return error;
|
components/editor/save-button/index.tsx
CHANGED
|
@@ -55,7 +55,7 @@ export function SaveButton({
|
|
| 55 |
return (
|
| 56 |
<>
|
| 57 |
<Button
|
| 58 |
-
variant="
|
| 59 |
className="max-lg:hidden !px-4"
|
| 60 |
onClick={updateSpace}
|
| 61 |
>
|
|
@@ -64,7 +64,7 @@ export function SaveButton({
|
|
| 64 |
{loading && <Loading className="ml-2 size-4 animate-spin" />}
|
| 65 |
</Button>
|
| 66 |
<Button
|
| 67 |
-
variant="
|
| 68 |
size="sm"
|
| 69 |
className="lg:hidden"
|
| 70 |
onClick={updateSpace}
|
|
|
|
| 55 |
return (
|
| 56 |
<>
|
| 57 |
<Button
|
| 58 |
+
variant="default"
|
| 59 |
className="max-lg:hidden !px-4"
|
| 60 |
onClick={updateSpace}
|
| 61 |
>
|
|
|
|
| 64 |
{loading && <Loading className="ml-2 size-4 animate-spin" />}
|
| 65 |
</Button>
|
| 66 |
<Button
|
| 67 |
+
variant="default"
|
| 68 |
size="sm"
|
| 69 |
className="lg:hidden"
|
| 70 |
onClick={updateSpace}
|
middleware.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { NextResponse } from "next/server";
|
| 2 |
+
import type { NextRequest } from "next/server";
|
| 3 |
+
|
| 4 |
+
export function middleware(request: NextRequest) {
|
| 5 |
+
const headers = new Headers(request.headers);
|
| 6 |
+
headers.set("x-current-host", request.nextUrl.host);
|
| 7 |
+
return NextResponse.next({ headers });
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
export const config = {
|
| 11 |
+
matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],
|
| 12 |
+
};
|