Error boundary

This commit is contained in:
PxlLoewe
2025-03-26 14:04:15 -07:00
parent 9551202370
commit c8d91b684f
21 changed files with 414 additions and 298 deletions

View File

@@ -3,8 +3,10 @@ import { redirect, useSearchParams } from "next/navigation";
import { Service } from "../page";
import { generateToken } from "./action";
import { useSession } from "next-auth/react";
import { useErrorBoundary } from "react-error-boundary";
export const Authorize = ({ service }: { service: Service }) => {
const { showBoundary } = useErrorBoundary();
const searchParams = useSearchParams();
const legitimeUrl = service.approvedUrls.some((url) =>
searchParams.get("redirect_uri")?.startsWith(url),
@@ -35,15 +37,19 @@ export const Authorize = ({ service }: { service: Service }) => {
type="submit"
className="btn btn-primary"
onClick={async () => {
const code = await generateToken(service);
const url = new URL(searchParams.get("redirect_uri") as string);
url.searchParams.append("code", code?.accessToken as string);
url.searchParams.append(
"state",
searchParams.get("state") as string,
);
try {
const code = await generateToken(service);
const url = new URL(searchParams.get("redirect_uri") as string);
url.searchParams.append("code", code?.accessToken as string);
url.searchParams.append(
"state",
searchParams.get("state") as string,
);
window.location.href = url.href;
window.location.href = url.href;
} catch (error) {
showBoundary(error);
}
}}
>
Zulassen