Hi again,
Alright so most of the steps are actually on the Github page of Pyrebase but this is the one I’m using:
Seeing as you already have the login working I’m assuming that you know how to setup the Firebase project, register account and e-mail login, please let me know if you need help with that too
In my logic for the on_submit of the register account form I have a check that if the account registration was successful, I immediately follow-up with the verification mail method.
I pass the email and password of the newly registered account along to the verification mail method cause we need it for the login method since we need the result it returns to send the verification mail.
So the end result looks a little something like this(where auth holds a reference to the firebase authentication object):
def page_create_account(self, auth):
st.markdown("### $1000000000 for an account pls :money_with_wings:")
with st.form(key='register_form'):
email = st.text_input("Just kidding we only need your email for this test :D")
password = st.text_input("Password", type="password")
confirm_password = st.text_input("Confirm password", type="password")
submit_button = st.form_submit_button(label="Submit")
if submit_button:
# Put your own checks for empty/wrongly filled register account form fields here
if auth.create_user_with_email_and_password(email, password):
# Put your own checks for a successful registered account here
result = auth.sign_in_with_email_and_password(email, password)
# The line below actually sends the verification mail
auth.send_email_verification(result["idToken"])
st.success("kaching! account created :eyes:, please verify your e-mail address with the link that we've mailed you!")
As you can see we get a user object/result from the sign_in method, this contains the idToken that we send along with the send_email_verification method so we can send out the mail.
To get more info about the verification status of the e-mail you can use a check like below:
user_obj = auth.get_account_info(result["idToken"])
email_verified = user_obj["users"][0]["emailVerified"]
if email_verified:
return True
else:
st.error("Please verify your e-mail address.")
return False
It’s a bit simplified since I’ve abstracted away most of my auth methods in its own auth.py script but I hope it helps you implement the verification mails!
Let me know if it works or not