import icon from "data-base64:~assets/icon.png"; import { Storage } from "@plasmohq/storage"; import { ReloadIcon } from "@radix-ui/react-icons"; import { useState } from "react"; import { useNavigate } from "react-router-dom"; import { Button } from "~/routes/ui/button"; const ApiKeyForm = () => { const navigation = useNavigate(); const [apiKey, setApiKey] = useState(""); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); const storage = new Storage({ area: "local" }); const validateForm = () => { if (!apiKey) { setError("API key is required"); return false; } setError(""); return true; }; const handleSubmit = async (event: { preventDefault: () => void }) => { event.preventDefault(); if (!validateForm()) return; setLoading(true); try { // Verify token is valid by making a request to the API const response = await fetch(`${process.env.PLASMO_PUBLIC_BACKEND_URL}/verify-token`, { method: "GET", headers: { Authorization: `Bearer ${apiKey}`, }, }); setLoading(false); if (response.ok) { // Store the API key as the token await storage.set("token", apiKey); navigation("/"); } else { setError("Invalid API key. Please check and try again."); } } catch (error) { setLoading(false); setError("An error occurred. Please try again later."); } }; return (
SurfSense

SurfSense

Enter your API Key

Your API key connects this extension to the SurfSense.

setApiKey(e.target.value)} className="w-full px-3 py-2 bg-gray-900/50 border border-gray-700 rounded-md focus:outline-none focus:ring-2 focus:ring-teal-500 text-white placeholder:text-gray-500" placeholder="Enter your API key" /> {error &&

{error}

}

Need an API key?{" "} Sign up

); }; export default ApiKeyForm;