added nextclud oAuth
This commit is contained in:
@@ -4,6 +4,8 @@ import { Service } from "../page";
|
||||
import { generateToken } from "./action";
|
||||
import { useSession } from "next-auth/react";
|
||||
import { useErrorBoundary } from "react-error-boundary";
|
||||
import { se } from "date-fns/locale";
|
||||
import { PERMISSION } from "@repo/db";
|
||||
|
||||
export const Authorize = ({ service }: { service: Service }) => {
|
||||
const { showBoundary } = useErrorBoundary();
|
||||
@@ -12,8 +14,7 @@ export const Authorize = ({ service }: { service: Service }) => {
|
||||
searchParams.get("redirect_uri")?.startsWith(url),
|
||||
);
|
||||
const { data: session } = useSession();
|
||||
if (!session)
|
||||
redirect("/login?redirect=" + encodeURIComponent(window.location.href));
|
||||
if (!session) redirect("/login?redirect=" + encodeURIComponent(window.location.href));
|
||||
if (!legitimeUrl)
|
||||
return (
|
||||
<div className="card-body">
|
||||
@@ -21,13 +22,24 @@ export const Authorize = ({ service }: { service: Service }) => {
|
||||
<p>Du greifst von einem nicht genehmigtem Server auf diese URL zu</p>
|
||||
</div>
|
||||
);
|
||||
if (
|
||||
service.requiredPermissions &&
|
||||
!service.requiredPermissions.every((p) => session.user.permissions.includes(p as PERMISSION))
|
||||
)
|
||||
return (
|
||||
<div className="card-body">
|
||||
<h1 className="text-4xl font-bold">Fehlende Berechtigung</h1>
|
||||
<p>
|
||||
Du hast nicht die erforderlichen Berechtigungen, um dich auf diesem Service anzumelden.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<form className="card-body" onSubmit={(e) => e.preventDefault()}>
|
||||
<h1 className="text-4xl font-bold">Zugriff zulassen</h1>
|
||||
<p>
|
||||
Die Anwendung <strong>{service.name}</strong> möchte auf deine Daten
|
||||
zugreifen.
|
||||
Die Anwendung <strong>{service.name}</strong> möchte auf deine Daten zugreifen.
|
||||
</p>
|
||||
<div className="space-x-4">
|
||||
<button type="button" className="btn">
|
||||
@@ -41,10 +53,7 @@ export const Authorize = ({ service }: { service: Service }) => {
|
||||
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,
|
||||
);
|
||||
url.searchParams.append("state", searchParams.get("state") as string);
|
||||
|
||||
window.location.href = url.href;
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user