-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add Firebase authentication for Merchant Sign Up #54
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not couple firebase with our component! Here's what you can do:
- Initialise firebase in a
firebase.ts
file inweb/src
. This file should contain thefirebase.initializeApp()
line and things likeconst auth = firebase.auth;
and export it and use that instead.
Other comments:
- Change to use react hooks and Functional Components! :D
- Using arrow functions will remove the need for binding so we can remove
autobind
as well.
…y-group-buy into karen/firebase-sign-up
web/src/constants/sign-up-errors.ts
Outdated
const PASSWORDS_DO_NOT_MATCH = 'Passwords do not match.'; | ||
|
||
const INVALID_EMAIL = 'Please input a valid email address.'; | ||
const WEAK_PASSWORD = 'Password should be at least 6 characters.'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this error? Is there a error msg sent from firebase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah firebase has these errors.
setConfirmPassword(event.target.value); | ||
}; | ||
|
||
const handleVpaChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
event.target.value ? setVpaError('') : setVpaError(VPA_EMPTY); | ||
event.target.value ? setVpaError('') : setVpaError(Errors.VPA_EMPTY); | ||
setVpa(event.target.value); | ||
}; | ||
|
||
const handleSubmit = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you disable the submit button if there is some error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay!
setConfirmPasswordError(Errors.PASSWORDS_DO_NOT_MATCH); | ||
if (!vpa) setVpaError(Errors.VPA_EMPTY); | ||
|
||
if (!name || !email || !password || password !== confirmPassword || !vpa) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to avoid doing a second time check here? If there is a growing list of validation checks (e.g., 20 items), this is a long line of repetition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to using library so we don't have to do this.
try { | ||
await firebaseAuth.createUserWithEmailAndPassword(email, password); | ||
} catch (error) { | ||
if (error.code === 'auth/invalid-email') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can change to switch statement?
"Generally speaking, if-else is best used when there are two discrete values or a few different ranges of values for which to test. When there are more than two discrete values for which to test, the switch statement is the most optimal choice" - source
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay! Yep, switch-case is better in this case.
…y-group-buy into karen/firebase-sign-up
…y-group-buy into karen/firebase-sign-up
We decided to use Firebase to handle authentication since it has a lot of authentication capabilities.
This PR adds Firebase code to handle authentication when merchant signs up.
This also stores merchant's account to Firebase so merchant can sign in with then same account in the future.
Some additional feature given by Firebase Authentication is checking email format, password strength and if existing user has the same email.