import { t } from "@lingui/core/macro"
import { Trans, useLingui } from "@lingui/react/macro"
import { KeyRoundIcon, LoaderCircleIcon, ShieldXIcon } from "lucide-react"
import { useState } from "react"
import { TokenValue } from "@/components/token-value"
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog"
import { Button, buttonVariants } from "@/components/ui/button"
import { Label } from "@/components/ui/label"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import { Separator } from "@/components/ui/separator"
import { toast } from "@/components/ui/use-toast"
import { pb } from "@/lib/api"
import { cn, formatTimeUnit, getHubURL } from "@/lib/utils"
const DAY = 24 * 60 * 60
const NEVER = "never"
function showError(error: unknown) {
toast({
title: t`Error`,
description: (error as Error).message,
variant: "destructive",
})
}
export default function ApiKeysSettings() {
return (
API Keys
API keys let scripts and integrations use the Beszel API as your user. A key has the same access as your
account and works until it expires or is revoked.
)
}
function SectionRevoke() {
const [open, setOpen] = useState(false)
const [isLoading, setIsLoading] = useState(false)
async function revokeKeys() {
setIsLoading(true)
try {
const { token } = await pb.send<{ token: string }>("/api/beszel/api-keys/revoke", { method: "POST" })
// the old session token is now invalid, so keep this tab logged in with the new one
pb.authStore.save(token, pb.authStore.record)
// reload so realtime subscriptions reconnect with the new token
window.location.reload()
} catch (error) {
showError(error)
setIsLoading(false)
}
}
return (
Revoke API keys
Revoking invalidates all of your API keys and signs you out of other devices. Changing your password has the
same effect.
Revoke all API keys?
Every API key you have created will stop working immediately, and you will be signed out of other
devices.
CancelRevoke