All files / src/apps/home/pages/login Login.tsx

47.82% Statements 11/23
50% Branches 10/20
33.33% Functions 3/9
47.61% Lines 10/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169              1x           1x 2x 2x   2x 2x     2x         2x         2x                                                                                                                                                                           3x                                                                                                      
import { usePageMeta } from "@/contexts/PageContext";
import { useAuth } from "@/hooks/useAuth";
import { APP_NAME } from "@/routes/const";
import { CheckCircle2, LogIn, ShieldCheck, UserPlus, Zap } from "lucide-react";
import React, { useEffect } from "react";
import { BRAND_BLUE } from "@/components/theme/accents";
 
const BENEFITS = [
  "Manage and monitor your entire AI agent fleet",
  "Rules enforced on every invocation, with a full audit trail",
  "Evaluate every agent version before it answers",
];
 
const Login: React.FC = () => {
  usePageMeta("Login", false);
  const { isAuthenticated, loading } = useAuth();
 
  useEffect(() => {
    if (isAuthenticated) window.location.href = import.meta.env.VITE_APP_DOMAIN;
  }, [isAuthenticated]);
 
  const handleLogin = () => {
    const returnTo = import.meta.env.VITE_APP_DOMAIN;
    window.location.href = `${import.meta.env.VITE_AUTH_DOMAIN}/login?return_to=${encodeURIComponent(returnTo)}`;
  };
 
  const handleSignup = () => {
    const returnTo = import.meta.env.VITE_APP_DOMAIN;
    window.location.href = `${import.meta.env.VITE_AUTH_DOMAIN}/login?return_to=${encodeURIComponent(returnTo)}&screen_hint=signup`;
  };
 
  return (
    <div className="min-h-[80vh] flex items-center justify-center px-6 py-20">
      <div className="w-full max-w-4xl">
        {/* Header */}
        <div className="text-center mb-12">
          <div
            className="inline-flex items-center gap-2 mb-6 px-4 py-1.5 rounded-full text-xs font-semibold tracking-widest uppercase"
            style={{
              background: "rgba(59,130,246,0.08)",
              border: "1px solid rgba(59,130,246,0.25)",
            }}
          >
            <ShieldCheck className="size-3" />
            Secure Authentication
          </div>
          <h1
            className="text-3xl md:text-5xl font-black mb-4 leading-tight"
            style={{
              background: "linear-gradient(135deg, #1e40af 0%, #3b82f6 55%, #06b6d4 100%)",
              WebkitBackgroundClip: "text",
              WebkitTextFillColor: "transparent",
              backgroundClip: "text",
            }}
          >
            Welcome Back
          </h1>
          <p className="text-gray-500">
            Sign in to your {APP_NAME} account to continue.
          </p>
        </div>
 
        {isAuthenticated ? (
          <div
            className="max-w-sm mx-auto flex items-center gap-3 rounded-2xl p-5"
            style={{ border: "1px solid rgba(34,197,94,0.3)", background: "rgba(34,197,94,0.06)" }}
          >
            <CheckCircle2 className="size-5 shrink-0" style={{ color: "#22c55e" }} />
            <span className="text-sm font-medium">You are already signed in.</span>
          </div>
        ) : (
          <div className="grid grid-cols-1 md:grid-cols-2 gap-6 max-w-3xl mx-auto">
            {/* Sign in card */}
            <div
              className="rounded-2xl p-8 flex flex-col gap-6"
              style={{
                background: "linear-gradient(160deg, #1e3a8a 0%, #1d4ed8 60%, #2563eb 100%)",
                boxShadow: "0 20px 60px rgba(37,99,235,0.35)",
              }}
            >
              <div>
                <h2 className="text-xl font-black text-white mb-1">Sign In</h2>
                <p className="text-sm" style={{ color: "rgba(255,255,255,0.65)" }}>
                  Access your existing account.
                </p>
              </div>
              <button
                disabled={loading}
                onClick={handleLogin}
                className="flex items-center justify-center gap-2 w-full rounded-xl font-bold py-3.5 px-5 text-sm transition-all"
                style={{
                  background: "white",
                  color: "#1d4ed8",
                  border: "none",
                  cursor: loading ? "not-allowed" : "pointer",
                  opacity: loading ? 0.6 : 1,
                  transition: "transform 0.15s",
                }}
                onMouseEnter={(e) => { if (!loading) e.currentTarget.style.transform = "scale(1.02)"; }}
                onMouseLeave={(e) => { e.currentTarget.style.transform = "scale(1)"; }}
              >
                <LogIn className="size-4" />
                {loading ? "Loading..." : "Login"}
              </button>
            </div>
 
            {/* Sign up card */}
            <div
              className="rounded-2xl p-8 flex flex-col gap-6"
              style={{ border: "1px solid rgba(59,130,246,0.18)" }}
            >
              <div>
                <h2 className="text-xl font-black mb-1">New to {APP_NAME}?</h2>
                <p className="text-sm text-gray-500">Create a free account in seconds.</p>
              </div>
              <ul className="flex flex-col gap-2.5">
                {BENEFITS.map((b) => (
                  <li key={b} className="flex items-start gap-2.5 text-sm text-gray-500">
                    <Zap className="size-3.5 mt-0.5 shrink-0" style={{ color: BRAND_BLUE }} />
                    {b}
                  </li>
                ))}
              </ul>
              <button
                disabled={loading}
                onClick={handleSignup}
                className="flex items-center justify-center gap-2 w-full rounded-xl font-bold py-3.5 px-5 text-sm transition-all"
                style={{
                  background: "rgba(37,99,235,0.08)",
                  color: "#1d4ed8",
                  border: "1px solid rgba(37,99,235,0.25)",
                  cursor: loading ? "not-allowed" : "pointer",
                  opacity: loading ? 0.6 : 1,
                  transition: "background 0.15s, transform 0.15s",
                }}
                onMouseEnter={(e) => {
                  if (!loading) {
                    e.currentTarget.style.background = "rgba(37,99,235,0.14)";
                    e.currentTarget.style.transform = "scale(1.02)";
                  }
                }}
                onMouseLeave={(e) => {
                  e.currentTarget.style.background = "rgba(37,99,235,0.08)";
                  e.currentTarget.style.transform = "scale(1)";
                }}
              >
                <UserPlus className="size-4" />
                {loading ? "Loading..." : "Create Account"}
              </button>
              <p className="text-xs text-center text-gray-400">
                Already have an account?{" "}
                <button
                  onClick={handleLogin}
                  className="font-semibold"
                  style={{ color: "#2563eb", background: "none", border: "none", cursor: "pointer", padding: 0 }}
                >
                  Sign in above
                </button>
              </p>
            </div>
          </div>
        )}
      </div>
    </div>
  );
};
 
export default Login;