Skip to content

armgit / kokon

Public Imported from GitHub
0

Edit photos by describing the change, on your own GPU. A free, open-source alternative to Nano Banana and ChatGPT image editing: photos stay on your computer, no daily limit. One installer for Windows, Mac and Linux sets up the best open model (Qwen-Image 2.1). MCP server for AI agents.

2.3 KB
Raw Blame
// Sign-in for Kokon opened in a browser on another device: the password set in the desktop app
// (Settings → Other devices) or with `kokon-service --set-password`. Once per browser; the
// session lasts 90 days or until the password changes.

import { useEffect, useRef, useState } from "react";
import { ApiError, api } from "../lib/api";
import { KokonMark } from "./Welcome";

export function Login({ onSignedIn }: { onSignedIn: () => void }) {
  const [password, setPassword] = useState("");
  const [busy, setBusy] = useState(false);
  const [error, setError] = useState<string | null>(null);
  const [noPassword, setNoPassword] = useState(false);
  const input = useRef<HTMLInputElement>(null);

  useEffect(() => {
    api.session().then((s) => setNoPassword(!s.password_set), () => {});
    input.current?.focus();
  }, []);

  const submit = async (e: React.FormEvent) => {
    e.preventDefault();
    if (!password || busy) return;
    setBusy(true);
    setError(null);
    try {
      await api.login(password);
      onSignedIn();
    } catch (err) {
      setError(err instanceof ApiError ? err.body.message : "Kokon is not reachable.");
      setPassword("");
      input.current?.focus();
    } finally {
      setBusy(false);
    }
  };

  return (
    <form className="login" onSubmit={submit}>
      <KokonMark size={48} />
      <strong>Sign in to Kokon</strong>
      {noPassword ? (
        <span className="muted">No password is set yet. On the computer running Kokon, open Settings → Other devices and set one.</span>
      ) : (
        <>
          <span className="muted">Enter the password set on the computer running Kokon. This browser stays signed in.</span>
          <input
            ref={input}
            className="input"
            type="password"
            autoComplete="current-password"
            placeholder="Password"
            aria-label="Password"
            value={password}
            onChange={(e) => setPassword(e.target.value)}
          />
          {error && (
            <span className="login-error" role="alert">
              {error}
            </span>
          )}
          <button className="btn primary" type="submit" disabled={!password || busy}>
            {busy ? "Signing in…" : "Sign in"}
          </button>
        </>
      )}
    </form>
  );
}