fix: fixed redirecting
Build and Deploy / test-backend (push) Successful in 1m15s
Build and Deploy / lint-frontend (push) Successful in 1m13s
Build and Deploy / build-backend (push) Successful in 50s
Build and Deploy / build-frontend (push) Successful in 40s
Build and Deploy / deploy (push) Successful in 6s

This commit is contained in:
Ivan Rezchikov
2026-09-17 13:12:54 +03:00
parent 6347e108fe
commit 2597e5b352
2 changed files with 5 additions and 8 deletions
@@ -32,7 +32,7 @@ func (h *OAuthHandler) Authorize(c *gin.Context) {
return 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) { func (h *OAuthHandler) GetSession(c *gin.Context) {
+4 -7
View File
@@ -9,10 +9,10 @@ export async function proxy(request: NextRequest) {
const isPublicPath = PUBLIC_PATHS.includes(pathname); const isPublicPath = PUBLIC_PATHS.includes(pathname);
const session = request.nextUrl.searchParams.get("session"); const session = request.nextUrl.searchParams.get("session");
if (session && pathname === "/login") { if (hasRefreshToken && session && pathname === "/login") {
const accessToken = request.cookies.get("access_token")?.value; const accessToken = request.cookies.get("access_token")?.value;
try { 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", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
@@ -20,6 +20,7 @@ export async function proxy(request: NextRequest) {
}, },
body: JSON.stringify({ session }), body: JSON.stringify({ session }),
}); });
if (!res.ok) throw new Error("attach failed");
} catch (error) { } catch (error) {
console.error("Failed to attach session:", error); console.error("Failed to attach session:", error);
return NextResponse.redirect(new URL("/callback/error", request.url)); 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)); return NextResponse.redirect(new URL(`/consent?session=${session}`, request.url));
} }
if (session && pathname === "/consent") { if (hasRefreshToken && (isPublicPath || pathname === "/")) {
return NextResponse.next();
}
if (hasRefreshToken && !session && (isPublicPath || pathname === "/")) {
return NextResponse.redirect(new URL("/me", request.url)); return NextResponse.redirect(new URL("/me", request.url));
} }