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
+4 -7
View File
@@ -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));
}