From 206bbb1f7c9e8777b4037a1501a375fc12bd8f1a Mon Sep 17 00:00:00 2001 From: testusuke Date: Sun, 6 Oct 2024 20:25:21 +0900 Subject: [PATCH 1/6] =?UTF-8?q?fix:=20=E3=83=9F=E3=83=89=E3=83=AB=E3=82=A6?= =?UTF-8?q?=E3=82=A7=E3=82=A2=E3=81=AE=E3=83=AA=E3=83=80=E3=82=A4=E3=83=AC?= =?UTF-8?q?=E3=82=AF=E3=83=88=E5=87=A6=E7=90=86=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- middleware.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/middleware.ts b/middleware.ts index 1695f1f..09cc6a5 100644 --- a/middleware.ts +++ b/middleware.ts @@ -14,7 +14,13 @@ export function middleware(request: NextRequest) { // check if next path starts with any of the protected paths or root if (protectedPaths.some(path => request.nextUrl.pathname.startsWith(path)) || request.nextUrl.pathname === '/') { - return NextResponse.redirect(new URL('/login', request.url)); + const subDirectory = process.env.SUB_DIRECTORY + if (subDirectory) { + return NextResponse.redirect(new URL(subDirectory + '/login', request.url)); + } + else { + return NextResponse.redirect(new URL('/login', request.url)); + } } } From 899291ca6c1ecf04a73460ce06104d44aec1c7f6 Mon Sep 17 00:00:00 2001 From: testusuke Date: Sun, 6 Oct 2024 22:12:29 +0900 Subject: [PATCH 2/6] =?UTF-8?q?debug:=20authCallback=E3=81=AB=E3=83=87?= =?UTF-8?q?=E3=83=90=E3=83=83=E3=82=AF=E3=82=B3=E3=83=BC=E3=83=89=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/auth/callback/route.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/api/auth/callback/route.ts b/app/api/auth/callback/route.ts index 022aa8d..5e74a70 100644 --- a/app/api/auth/callback/route.ts +++ b/app/api/auth/callback/route.ts @@ -1,17 +1,27 @@ import {NextRequest} from "next/server" export async function POST(request: NextRequest) { + console.log("Auth Endpoint.") + // form data const form = await request.formData() // get state and code const code = form.get('code') + console.log("Code is ", code) + // pass code to the backend const loginEndpoint = process.env.NEXT_PUBLIC_API_URL + '/login' + console.log("Login Endpoint ", loginEndpoint) + // redirect uri const redirectUri = process.env.NEXT_PUBLIC_OIDC_REDIRECT_URL + console.log("Redirect URL ", redirectUri) + + console.log("Post Backend API") + // post code to the backend using fetch const response = await fetch(loginEndpoint, { method: 'POST', @@ -24,9 +34,13 @@ export async function POST(request: NextRequest) { }), }) + console.log("Fetch done") + // get cookie from response const cookie = response.headers.get('set-cookie') + console.log("cookie", cookie) + if (cookie) { // redirect to root page return new Response(null, { From f182024799079c2bfd13fa5eb9ba72559344ad92 Mon Sep 17 00:00:00 2001 From: testusuke Date: Sun, 6 Oct 2024 23:03:19 +0900 Subject: [PATCH 3/6] =?UTF-8?q?change:=20=E3=82=B5=E3=83=BC=E3=83=90?= =?UTF-8?q?=E3=83=BC=E3=82=B5=E3=82=A4=E3=83=89=E3=81=8B=E3=82=89=E3=81=AE?= =?UTF-8?q?=E3=83=90=E3=83=83=E3=82=AF=E3=82=A8=E3=83=B3=E3=83=89URL?= =?UTF-8?q?=E3=82=92=E5=A4=89=E6=9B=B4=E5=8F=AF=E8=83=BD=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/auth/callback/route.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/api/auth/callback/route.ts b/app/api/auth/callback/route.ts index 5e74a70..1ba3a74 100644 --- a/app/api/auth/callback/route.ts +++ b/app/api/auth/callback/route.ts @@ -11,7 +11,8 @@ export async function POST(request: NextRequest) { console.log("Code is ", code) // pass code to the backend - const loginEndpoint = process.env.NEXT_PUBLIC_API_URL + '/login' + const backendURL = process.env.NEXT_PUBLIC_API_INTERNAL_URL ? process.env.NEXT_PUBLIC_API_INTERNAL_URL : process.env.NEXT_PUBLIC_API_URL + const loginEndpoint = backendURL + '/login' console.log("Login Endpoint ", loginEndpoint) From dd990421fbe83ef203f6bc18e1e5e22240abf2b3 Mon Sep 17 00:00:00 2001 From: testusuke Date: Sun, 6 Oct 2024 23:08:05 +0900 Subject: [PATCH 4/6] =?UTF-8?q?fix:=20=E3=83=AD=E3=82=B0=E3=82=A4=E3=83=B3?= =?UTF-8?q?=E5=BE=8C=E3=81=AB=E8=AA=A4=E3=81=A3=E3=81=9F=E3=83=91=E3=82=B9?= =?UTF-8?q?=E3=81=AB=E7=A7=BB=E5=8B=95=E3=81=99=E3=82=8B=E5=95=8F=E9=A1=8C?= =?UTF-8?q?=E3=82=92=E8=A7=A3=E6=B1=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/auth/callback/route.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/api/auth/callback/route.ts b/app/api/auth/callback/route.ts index 1ba3a74..491ef4f 100644 --- a/app/api/auth/callback/route.ts +++ b/app/api/auth/callback/route.ts @@ -42,12 +42,14 @@ export async function POST(request: NextRequest) { console.log("cookie", cookie) + const subDirectory = process.env.SUB_DIRECTORY ? process.env.SUB_DIRECTORY : "/" + if (cookie) { // redirect to root page return new Response(null, { status: 301, headers: { - "Location": '/', + "Location": subDirectory, "Set-Cookie": cookie, }, }) @@ -57,7 +59,7 @@ export async function POST(request: NextRequest) { return new Response(null, { status: 301, headers: { - "Location": '/', + "Location": subDirectory, }, }) } From b1bde419824f00ac09bdd24e428c79e825ae147c Mon Sep 17 00:00:00 2001 From: testusuke Date: Sun, 6 Oct 2024 23:12:46 +0900 Subject: [PATCH 5/6] =?UTF-8?q?change:=20fetch=E3=82=92=E8=A1=8C=E3=81=86?= =?UTF-8?q?=E5=A0=B4=E6=89=80=E3=81=AB=E5=BF=9C=E3=81=98=E3=81=A6API?= =?UTF-8?q?=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/ApiClient.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/ApiClient.ts b/src/lib/ApiClient.ts index 9b13211..132e9fe 100644 --- a/src/lib/ApiClient.ts +++ b/src/lib/ApiClient.ts @@ -1,4 +1,5 @@ const ApiUrl = process.env.NEXT_PUBLIC_API_URL; +const ApiInternalUrl = process.env.NEXT_PUBLIC_API_INTERNAL_URL ? process.env.NEXT_PUBLIC_API_INTERNAL_URL : ApiUrl; const headers = { "Content-Type": "application/json", @@ -24,7 +25,7 @@ async function fetchWithToken(url: string, options: RequestInit | undefined = {} } try { - const fullUrl = `${ApiUrl}${url}` + const fullUrl = typeof window === 'undefined' ? `${ApiInternalUrl}${url}` : `${ApiUrl}${url}` const response = await fetch(fullUrl, mergedOptions); // Check if the response was ok (status in the range 200-299) From bfdad44d6ee256549b39871a530a96cff613f3b4 Mon Sep 17 00:00:00 2001 From: testusuke Date: Sun, 6 Oct 2024 23:38:59 +0900 Subject: [PATCH 6/6] =?UTF-8?q?debug:=20=E3=83=87=E3=83=90=E3=83=83?= =?UTF-8?q?=E3=82=AF=E3=82=B3=E3=83=BC=E3=83=89=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/auth/callback/route.ts | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/app/api/auth/callback/route.ts b/app/api/auth/callback/route.ts index 491ef4f..5cb2af5 100644 --- a/app/api/auth/callback/route.ts +++ b/app/api/auth/callback/route.ts @@ -1,28 +1,18 @@ import {NextRequest} from "next/server" export async function POST(request: NextRequest) { - console.log("Auth Endpoint.") - // form data const form = await request.formData() // get state and code const code = form.get('code') - console.log("Code is ", code) - // pass code to the backend const backendURL = process.env.NEXT_PUBLIC_API_INTERNAL_URL ? process.env.NEXT_PUBLIC_API_INTERNAL_URL : process.env.NEXT_PUBLIC_API_URL const loginEndpoint = backendURL + '/login' - console.log("Login Endpoint ", loginEndpoint) - // redirect uri const redirectUri = process.env.NEXT_PUBLIC_OIDC_REDIRECT_URL - console.log("Redirect URL ", redirectUri) - - console.log("Post Backend API") - // post code to the backend using fetch const response = await fetch(loginEndpoint, { method: 'POST', @@ -35,15 +25,9 @@ export async function POST(request: NextRequest) { }), }) - console.log("Fetch done") - // get cookie from response const cookie = response.headers.get('set-cookie') - - console.log("cookie", cookie) - const subDirectory = process.env.SUB_DIRECTORY ? process.env.SUB_DIRECTORY : "/" - if (cookie) { // redirect to root page return new Response(null, {