I need to be able to figure out why did the listener fire - was it an initial sign up or sign in?
I tried using part of the user payload that comes with the callback. I tried comparing user.metadata.createdAt and user.metadata.lastLoginAt and this usually works - if I sign up, then sign out, and then sign in - it's all ok. But it is not ok when I sign up and then simply refresh the page.
Is there a way to see some metadata about when was the last time the auth status was changed or simple - to figure out if onAuthStateChanged fired because of a sign up or sign in.
Thanks!
The onAuthStateChanged() fires when the auth state changes, so that is indeed both for sign-ups and sign-ins.
If you want to distinguish between the two, you can:
then that you get back from the signIn.../createUser method.creationTime and lastSignInTime in the user.metadata. If they're the same, the user was just created.