"use client"; import * as React from "react"; import Link from "next/link"; import Image from "next/image"; import { useRouter } from "next/navigation"; import { Avatar, AvatarImage, AvatarFallback } from "@/components/ui/avatar"; import { Card, CardHeader, CardTitle, CardContent, CardDescription } from "@/components/ui/card"; import { Label } from "@/components/ui/label"; import { Button } from "@/components/ui/button"; import { Separator } from "@/components/ui/separator"; import { Spinner } from "@/components/ui/spinner"; import { ShieldCheck } from "lucide-react"; import { IconExternalLink, IconHomeFilled, IconUserCircle, IconUser, IconMail, IconChevronRight, IconCheck } from "@tabler/icons-react"; import permissions from "@/permissions.json"; export interface AuthorizeContainerProps { client_id: string; redirect_uri: string; response_type: string; scope: string; applicationName: string; applicationUrl: string; applicationLogo?: string; } export interface AuthorizeLoadingProps { applicationName: string; applicationLogo?: string; applicationUrl: string; } export interface ScopePermission { name: string; description: string; } export const ScopePermissionComponent = (props: ScopePermission) => { const { name, description } = props; return (

{description}

); }; export const AuthorizeLoading = (props: AuthorizeLoadingProps) => { const { applicationName, applicationLogo } = props; return (
{applicationLogo && {applicationName}} {!applicationLogo && ( )}
); }; export const AuthorizeContainer = (props: AuthorizeContainerProps) => { const [isLoading, setIsLoading] = React.useState(true); const [user, setUser] = React.useState<{ username: string, email: string } | null>(null); const router = useRouter(); // const handleLogout = async () => { // const response = await fetch("/api/logout"); // const data = await response.json(); // if (data.success) { // toast.success(data.message); // router.refresh(); // } else { // toast.error(data.message); // } // }; // Get for each scope the permission name and description const scopePermissions = React.useMemo(() => { return props.scope.split(" ").map((scope) => { return { name: permissions[scope as keyof typeof permissions].name, description: permissions[scope as keyof typeof permissions].description, }; }); }, [props.scope]); React.useEffect(() => { const checkSession = async () => { const response = await fetch("/api/session"); const data = await response.json(); if (data.success) { setUser(data.sessionInfo); setIsLoading(false); } else { router.push("/"); } }; checkSession(); }, [router]); if (isLoading) { return ; } return (
{props.applicationName.charAt(0).toUpperCase()}

{props.applicationName}

{props.applicationUrl}

{user?.email}

{scopePermissions.map((permission) => ( ))}

By authorizing this application, you agree to the Terms of Service and Privacy Policy.

) }