diff --git a/kotosoft-id-backend/internal/handlers/oauth.go b/kotosoft-id-backend/internal/handlers/oauth.go index 37ce69f..e397df3 100644 --- a/kotosoft-id-backend/internal/handlers/oauth.go +++ b/kotosoft-id-backend/internal/handlers/oauth.go @@ -32,7 +32,7 @@ func (h *OAuthHandler) Authorize(c *gin.Context) { return } - c.Redirect(http.StatusFound, h.frontendURL+"/oauth?session="+token) + c.Redirect(http.StatusFound, h.frontendURL+"/login?session="+token) } func (h *OAuthHandler) GetSession(c *gin.Context) { diff --git a/kotosoft-id-frontend/proxy.ts b/kotosoft-id-frontend/proxy.ts index 829147b..a6c2d18 100644 --- a/kotosoft-id-frontend/proxy.ts +++ b/kotosoft-id-frontend/proxy.ts @@ -9,10 +9,10 @@ export async function proxy(request: NextRequest) { const isPublicPath = PUBLIC_PATHS.includes(pathname); const session = request.nextUrl.searchParams.get("session"); - if (session && pathname === "/login") { + if (hasRefreshToken && session && pathname === "/login") { const accessToken = request.cookies.get("access_token")?.value; try { - await fetch(`${process.env.KOTOSOFT_ID_API_URL}/oauth/session/attach`, { + const res = await fetch(`${process.env.KOTOSOFT_ID_API_URL}/oauth/session/attach`, { method: "POST", headers: { "Content-Type": "application/json", @@ -20,6 +20,7 @@ export async function proxy(request: NextRequest) { }, body: JSON.stringify({ session }), }); + if (!res.ok) throw new Error("attach failed"); } catch (error) { console.error("Failed to attach session:", error); return NextResponse.redirect(new URL("/callback/error", request.url)); @@ -27,11 +28,7 @@ export async function proxy(request: NextRequest) { return NextResponse.redirect(new URL(`/consent?session=${session}`, request.url)); } - if (session && pathname === "/consent") { - return NextResponse.next(); - } - - if (hasRefreshToken && !session && (isPublicPath || pathname === "/")) { + if (hasRefreshToken && (isPublicPath || pathname === "/")) { return NextResponse.redirect(new URL("/me", request.url)); }