Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Link Firebase Authentication to Volunteers Table #35

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/pages/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
FormControl,
FormErrorMessage,
FormLabel,
HStack,
Input,
Modal,
ModalBody,
Expand All @@ -24,6 +25,7 @@ import {
logInWithEmailAndPassWord,
sendResetPasswordPrompt,
} from '../utils/firebaseAuthUtils';
import Backend from '../utils/utils';

const Login = () => {
return (
Expand All @@ -43,6 +45,8 @@ const signinSchema = yup.object({
});

const signupSchema = yup.object({
firstName: yup.string().required("Please enter your first name"),
lastName: yup.string().required("Please enter your last name"),
email: yup.string().email().required('Please enter your email address'),
password: yup
.string()
Expand Down Expand Up @@ -146,10 +150,11 @@ const CreateAccount = () => {
const navigate = useNavigate();

const onSubmit = async event => {
const { email, password } = event;
const { email, password, firstName, lastName } = event;

try {
await createUserInFirebase(email, password, '/successful-login', navigate);
await createVolunteerRow({id: email, email, firstName, lastName});

toast.closeAll();

Expand Down Expand Up @@ -188,6 +193,18 @@ const CreateAccount = () => {
<ModalCloseButton />
<ModalBody>
<form onSubmit={handleSubmit(onSubmit)}>
<HStack>
<FormControl isInvalid={errors.firstName}>
<FormLabel>First Name</FormLabel>
<Input type="text" {...register('firstName')} />
{errors.firstName && <FormErrorMessage>{errors.firstName?.message}</FormErrorMessage>}
</FormControl>
<FormControl isInvalid={errors.lastName}>
<FormLabel>Last Name</FormLabel>
<Input type="text" {...register('lastName')} />
{errors.lastName && <FormErrorMessage>{errors.lastName?.message}</FormErrorMessage>}
</FormControl>
</HStack>
<FormControl isInvalid={errors.email}>
<FormLabel>Email address</FormLabel>
<Input type="email" {...register('email')} />
Expand Down Expand Up @@ -222,6 +239,16 @@ const CreateAccount = () => {
);
};

const createVolunteerRow = async ({ id, email, firstName, lastName }) => {
const response = await Backend.post("/profiles", {
id: id,
email: email,
first_name: firstName,
last_name: lastName,
});
return response;
};

const ForgotPasswordButton = () => {
const { isOpen, onOpen, onClose } = useDisclosure();
const [email, setEmail] = useState('');
Expand Down
Loading