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
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:
@@ -11,6 +11,9 @@ export async function proxy(request: NextRequest) {
|
|||||||
|
|
||||||
if (hasRefreshToken && session && pathname === "/login") {
|
if (hasRefreshToken && session && pathname === "/login") {
|
||||||
const accessToken = request.cookies.get("access_token")?.value;
|
const accessToken = request.cookies.get("access_token")?.value;
|
||||||
|
if (!accessToken) {
|
||||||
|
return NextResponse.next();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const res = 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",
|
||||||
@@ -21,6 +24,10 @@ export async function proxy(request: NextRequest) {
|
|||||||
body: JSON.stringify({ session }),
|
body: JSON.stringify({ session }),
|
||||||
});
|
});
|
||||||
if (!res.ok) throw new Error("attach failed");
|
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) {
|
} 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));
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user