import React, { useState } from "react"; import { useNavigate } from "react-router-dom" import icon from "data-base64:~assets/icon.png" import { Storage } from "@plasmohq/storage" import { Button } from "~/routes/ui/button" import { ReloadIcon } from "@radix-ui/react-icons" 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 (
Your API key connects this extension to the SurfSense.
Need an API key?{" "} Sign up