Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Commit

Permalink
Use route handler instead of page for SSO
Browse files Browse the repository at this point in the history
  • Loading branch information
wil93 committed Oct 9, 2024
1 parent d52b8a4 commit a683a3b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
25 changes: 0 additions & 25 deletions src/app/sso/page.tsx

This file was deleted.

31 changes: 31 additions & 0 deletions src/app/sso/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { getForumSso } from "@olinfo/training-api";
import { redirect } from "next/navigation";
import { type NextRequest, NextResponse } from "next/server";

export async function GET(request: NextRequest) {
const token = request.cookies.get("training_token")?.value;

// User is logged out.
if (token === undefined) {
const redirectUrl = request.nextUrl.pathname + request.nextUrl.search;
redirect(`/login?redirect=${encodeURIComponent(redirectUrl)}`);
}

const payload = request.nextUrl.searchParams.get("sso");
const signature = request.nextUrl.searchParams.get("sig");

if (payload === null || signature === null) {
return NextResponse.json(
{ message: "Parameters sso and sig must be provided." },
{ status: 400 },
);
}

const { return_sso_url: returnSsoUrl, parameters } = await getForumSso(
payload,
signature,
`training_token=${token}`,
);

redirect(`${returnSsoUrl}?${parameters}`);
}

0 comments on commit a683a3b

Please sign in to comment.