Skip to content
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

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

Open
CalebMacdonaldBlack opened this issue Jun 22, 2018 · 3 comments

Comments

@CalebMacdonaldBlack
Copy link

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
Copy link
Owner

deg commented Jun 25, 2018

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
Copy link
Contributor

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
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants