import React, { useCallback } from "react" import { apiFetch } from "src/api" import { NodeData } from "src/hooks/node-data" import { ReactComponent as TailscaleIcon } from "src/icons/tailscale-icon.svg" /** * LoginView is rendered when the client is not authenticated * to a tailnet. */ export default function LoginView({ data, refreshData, }: { data: NodeData refreshData: () => void }) { const login = useCallback( (opt: TailscaleUpOptions) => { tailscaleUp(opt).then(refreshData) }, [refreshData] ) return (
{data.Status == "Stopped" ? ( <>

Connect

Your device is disconnected from Tailscale.

) : data.IP ? ( <>

Your device's key has expired. Reauthenticate this device by logging in again, or{" "} learn more .

) : ( <>

Log in

Get started by logging in to your Tailscale network. Or, learn more at{" "} tailscale.com .

)}
) } type TailscaleUpOptions = { Reauthenticate?: boolean // force reauthentication } function tailscaleUp(options: TailscaleUpOptions) { return apiFetch("/up", "POST", options) .then((r) => r.json()) .then((d) => { d.url && window.open(d.url, "_blank") }) .catch((e) => { console.error("Failed to login:", e) }) }