MCPcopy Create free account
hub / github.com/CodeFox-Repo/codefox / SignInModal

Function SignInModal

frontend/src/components/sign-in-modal.tsx:34–186  ·  view source on GitHub ↗
({ isOpen, onClose }: SignInModalProps)

Source from the content-addressed store, hash-verified

32}
33
34export function SignInModal({ isOpen, onClose }: SignInModalProps) {
35 const [email, setEmail] = useState('');
36 const [password, setPassword] = useState('');
37 const [errorMessage, setErrorMessage] = useState<string | null>(null);
38 // Destructure login from our AuthContext
39 const { login } = useAuthContext();
40
41 // Destructure `loading` so we can disable the button while logging in
42 // Hidden entirely when the backend has no Google credentials — a button
43 // whose only outcome is an error toast is not a feature.
44 const { data: googleData } = useQuery(GOOGLE_AUTH_AVAILABLE);
45 const googleAvailable = googleData?.googleAuthAvailable ?? false;
46 const [loginUser, { loading }] = useMutation(LOGIN_USER, {
47 onCompleted: (data) => {
48 if (data?.login) {
49 // Store tokens where desired (session storage for access, local for refresh)
50 login(data.login.accessToken, data.login.refreshToken);
51 toast.success('Login successful!');
52 setErrorMessage(null);
53 onClose(); // Close the modal
54
55 // If you want to redirect somewhere on success, uncomment:
56 // router.push("/main");
57 }
58 },
59 onError: () => {
60 setErrorMessage('Incorrect email or password. Please try again.');
61 },
62 });
63
64 const handleSubmit = async (e: React.FormEvent) => {
65 e.preventDefault();
66 setErrorMessage(null); // Clear error when attempting login again
67 try {
68 await loginUser({
69 variables: {
70 input: {
71 email,
72 password,
73 },
74 },
75 });
76 } catch (error) {
77 logger.error('Login failed:', error);
78 }
79 };
80
81 return (
82 <Dialog open={isOpen} onOpenChange={onClose}>
83 <DialogContent className="sm:max-w-[425px] fixed top-[50%] left-[50%] transform -translate-x-[50%] -translate-y-[50%] p-0">
84 {/* Invisible but accessible DialogTitle and Description */}
85 <VisuallyHidden>
86 <DialogTitle>Sign In</DialogTitle>
87 <DialogDescription>
88 Sign in to your account by entering your credentials
89 </DialogDescription>
90 </VisuallyHidden>
91

Callers

nothing calls this directly

Calls 1

useAuthContextFunction · 0.90

Tested by

no test coverage detected