fix: oauth flow
Build and Deploy / test-backend (push) Successful in 1m5s
Build and Deploy / lint-frontend (push) Successful in 1m28s
Build and Deploy / build-backend (push) Successful in 3s
Build and Deploy / build-frontend (push) Successful in 41s
Build and Deploy / deploy (push) Successful in 5s

This commit is contained in:
Ivan Rezchikov
2026-09-17 23:50:36 +03:00
parent 2597e5b352
commit 63badb0857
2 changed files with 8 additions and 1 deletions
+7
View File
@@ -11,6 +11,9 @@ export async function proxy(request: NextRequest) {
if (hasRefreshToken && session && pathname === "/login") {
const accessToken = request.cookies.get("access_token")?.value;
if (!accessToken) {
return NextResponse.next();
}
try {
const res = await fetch(`${process.env.KOTOSOFT_ID_API_URL}/oauth/session/attach`, {
method: "POST",
@@ -21,6 +24,10 @@ export async function proxy(request: NextRequest) {
body: JSON.stringify({ session }),
});
if (!res.ok) throw new Error("attach failed");
const data = await res.json().catch(() => null);
if (data?.redirect_url) {
return NextResponse.redirect(new URL(data.redirect_url));
}
} catch (error) {
console.error("Failed to attach session:", error);
return NextResponse.redirect(new URL("/callback/error", request.url));
File diff suppressed because one or more lines are too long