deg / re-frame-firebase

Re-frame wrapper around Google's Firebase database
95 stars 32 forks source link

Error when creating email user but everything seems to be working #18

Open CalebMacdonaldBlack opened 6 years ago

CalebMacdonaldBlack commented 6 years ago
TypeError: Cannot read property 'email' of null
    at Object.com$degel$re_frame_firebase$auth$user [as user] (auth.cljs:23)
    at com$degel$re_frame_firebase$auth$set_user (auth.cljs:28)
    at v.g (auth.js:20)
    at gd (auth.js:23)
    at ea (auth.js:23)
    at wa.x.Ub (auth.js:22)
    at le (auth.js:16)

screen shot 2018-06-22 at 9 51 32 am

Look like it's failing to do first on the providerData js array. I seem to be logged in and authenticated and everything works.

(-> firebase-user .-providerData first .-email)
firebase.auth().getRedirectResult().then(x => console.log(x))
VM5503:1 {user: null}

Running the above code myself returns a null user which is then passed into the code throwing the error.

https://firebase.google.com/docs/reference/js/firebase.auth.Auth#getRedirectResult In the docs it says "If no redirect operation was called, returns a UserCredential with a null User." I think this make sense as the email provider doesn't need to redirect from 3rd party oauth. Perhaps this code:

  (-> (js/firebase.auth)
      (.getRedirectResult)
      (.then (fn on-user-credential [user-credential]
               (-> user-credential
                   (.-user)
                   set-user)))
      (.catch (core/default-error-handler))))

in com.degel.re-frame-firebase.auth/init-auth can be omitted when using the email provider? If this is the case I'd be happy to submit a PR to fix this.

deg commented 6 years ago

This sounds reasonable, but I'm not setup to easily test email login. Bringing @wneirynck into the conversation to comment, since he wrote the email support.

wneirynck commented 6 years ago

I'll have to look into it, but at first sight the code is not directly related to the email issue. But maybe, as a result of enabling the email authentication possibility, the redirect code is also invoked. I'll check it out.

Also, maybe I'm seeing it incorrectly, but I think the init-auth function is never called.

shen-tian commented 6 years ago

In PR #19 , I changed the parsing code for set-user to read like this:

    :email         (let [provider-data (.-providerData firebase-user)]
                      (when-not (empty? provider-data)
                        (-> provider-data first .-email)))}))

which was required, as not all auth flow returns with a non-empty providerData array. Think this solves the symptom of the problem, at least?