Error boundary
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user