Golf-Drill-Challenge-App / Golf-App

7 stars 0 forks source link

feat: Email Verification upon Signup #288

Closed solderq35 closed 3 weeks ago

solderq35 commented 1 month ago

When joining new team

solderq35 commented 1 month ago

Demo Vid: https://youtube.com/shorts/e6q_DAK7Q_g

Timeout didn't quite work so just clicked "join team" twice I think

solderq35 commented 1 month ago

TODO:

solderq35 commented 1 month ago

I think the current changes in Auth.js are extraneous and can be removed

FrankreedX commented 1 month ago

Find a better way to update currentUser.emailVerified

Maybe onAuthStateChanged?

solderq35 commented 1 month ago

New Demo Vid: https://youtu.be/yzMtmMPuigU

Intended Workflow: New User signs up (email verification sent) > User taps "Join Team" button (or taps "Resend Verification Email" if needed) > User is logged into the app and redirected to homescreen (onIdTokenChanged asynchronously watches for when the email is verified on the user server side)

solderq35 commented 1 month ago

PS does the "join team" and "resend email verification" buttons need debouncing? I noticed that "join team" seemed to trigger multiple times sometimes (like 3 times in a row rapidly, hence janky navigation after tapping "join team" button).

FrankreedX commented 1 month ago

PS does the "join team" and "resend email verification" buttons need debouncing? I noticed that "join team" seemed to trigger multiple times sometimes (like 3 times in a row rapidly, hence janky navigation after tapping "join team" button).

Yes, and it will be addressed in either debounce 2 (if simple) or debounce-n (if complex) once this PR is merged

FrankreedX commented 1 month ago

What is your plan to add button spinners for all of this PR's operations?

solderq35 commented 1 month ago

What is your plan to add button spinners for all of this PR's operations?

Assuming that "Join Team" button is hidden to user until email is verified, I guess we could make the "Resend Verification Email" button show a spinner animation until the email is finished sending?

For verified users, I suppose the "Join Team" button could show a spinner animation until all async operations were awaited (firestore operations etc)

FrankreedX commented 1 month ago

Ye it took a very long time for me when I tested it. It's helpful to know that the app received my input and is doing work instead of just trusting it.

solderq35 commented 1 month ago

07-25-2024 Progress

Screenshot

image

solderq35 commented 1 month ago

Fixed the below signout error (see screenshot), although not sure if this will cause excess re renders etc, maybe there is better solution.

image

solderq35 commented 1 month ago

image

Kind of got loading spinner working for sending verification email, and also kind of fixed bug where it was inconsistent if the new user would be directed to chooseTeam screen upon signup.

TODO:

FrankreedX commented 1 month ago

you gotta set the "textColor" for the spinner to change

solderq35 commented 1 month ago

Changed spinner color to white: image

I removed the dependency array from the unregisterAuthObserver useEffect due to it bugging out.

Basically you need to call user.reload() in order for the updated status to register. If you also put auth.currentUser (or whatever) in the useEffect dependency array, it causes an infinite feedback loop.

So now it does work but the user has to manually pulldown to refresh after they verified email

Maybe helpful for the useEffect / emailVerified / onIdTokenChanged issue:

solderq35 commented 4 weeks ago

I think the useEffect works as intended now (it automatically detects when you verified email and then shows "Join Team" button afterwards).

To resolve the issues mentioned in my previous comment, I had to set up a setInterval to reload the user and check for updates every 10 seconds.

Demo Video (read Youtube video description): https://youtu.be/KpHN71xhFfE

solderq35 commented 4 weeks ago

PS: I tried putting showSnackBar in the useEffect dependency Array, but it caused the "Email successfully verified" popup to not go away for some reason later, especially if I had waited about 20 or 30 seconds after signup to verify email.

So I am leaving it out of the dependency array for now.

image

solderq35 commented 3 weeks ago

Had to change the context/Auth.js useEffect from onAuthStateChanged to onIdTokenChanged in order to get currentUserVerified / setCurrentUserVerified to work as intended. Hopefully that doesn't cause too many re renders etc.