'use client'; import { signInWithEmail } from '@/utils/auth-helpers/server'; import { handleRequest } from '@/utils/auth-helpers/client'; import { useRouter } from 'next/navigation'; import { useState } from 'react'; import { Box, Button, Flex, FormLabel, Input, useColorModeValue, Link } from '@chakra-ui/react'; // Define prop type with allowPassword boolean interface EmailSignInProps { allowPassword: boolean; redirectMethod: string; disableButton?: boolean; } export default function EmailSignIn({ allowPassword, redirectMethod }: EmailSignInProps) { const router = redirectMethod === 'client' ? useRouter() : null; const [isSubmitting, setIsSubmitting] = useState(false); const textColor = useColorModeValue('navy.700', 'white'); const handleSubmit = async (e: React.FormEvent) => { setIsSubmitting(true); // Disable the button while the request is being handled await handleRequest(e, signInWithEmail, router); setIsSubmitting(false); }; return (
handleSubmit(e)}> Email
{allowPassword && ( Sign in with email and password Don't have an account? Sign up )}
); }