"use client";
import { useState } from "react";
import { KeyRound, Loader2, ExternalLink } from "lucide-react";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Button } from "@/components/ui/button";
import { useAuth } from "./auth-provider";
export function ApiKeyGate({ children }: { children: React.ReactNode }) {
const { status, loading, setToken } = useAuth();
if (loading) {
return (
);
}
if (status?.has_token) {
return <>{children}>;
}
return ;
}
function ApiKeyForm({
onSubmit,
}: {
onSubmit: (token: string) => Promise<{ success: boolean; error?: string }>;
}) {
const [token, setToken] = useState("");
const [error, setError] = useState(null);
const [submitting, setSubmitting] = useState(false);
async function handleSubmit(e: React.FormEvent) {
e.preventDefault();
if (!token.trim()) return;
setError(null);
setSubmitting(true);
const result = await onSubmit(token.trim());
if (!result.success) {
setError(result.error || "Failed to set token");
}
setSubmitting(false);
}
return (
Artifacts Dashboard
Enter your Artifacts MMO API token to get started.
);
}