import React, { useState } from "react";
import { Link } from "react-router-dom";
import { base44 } from "@/api/base44Client";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { LogIn, Mail, Lock, Loader2 } from "lucide-react";
import AuthLayout from "@/components/AuthLayout";
import GoogleIcon from "@/components/GoogleIcon";
import { safeReturnTo } from "@/lib/authReturnTo";
export default function Login() {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);
// Post-login destination (e.g. the MCP OAuth consent page sends users here
// with returnTo so the grant flow can resume). Same-origin paths only.
const returnTo = safeReturnTo();
const handleSubmit = async (e) => {
e.preventDefault();
setError("");
setLoading(true);
try {
await base44.auth.loginViaEmailPassword(email, password);
window.location.href = returnTo;
} catch (err) {
setError(err.message || "Invalid email or password");
} finally {
setLoading(false);
}
};
const handleGoogle = () => {
base44.auth.loginWithProvider("google", returnTo);
};
return (