0

I have a Polymer application in which I want to use Firebase auth. I have created a custom element with a <paper-dialog> with email and password form.

If I include <firebase-app> and <firebase-auth> elements in the custom element, I am able to authenticate the user. So far, so good.

The problem arises when I want to sign the user out from the application, with a button/function in the root element. I need to get hold of the <firebase-auth> element in order to call its signOut method. I find the <firebase-auth> element with $.id or $$('#id') but it returns null.

If I move the <firebase-auth> and <firebase-app> elements into the root element, then I have the same problem trying to access them from my custom sign-in element.

If I add just the <firebase-auth> element to both places, I get 'No app configured for auth' and if I add the <firebase-app> element to both as well, I get 'Default app already defined'.

How can I make this work?

kpg
  • 7,644
  • 6
  • 34
  • 67
  • Can you put a sample of your actual code that isn't working? From your description it's not clear exactly where the problem lies. – Michael Bleigh Aug 17 '16 at 21:17
  • The problem is that I have tried several solutions as described but am not able to make any of them work. I'm not sure that I can add code for each of the options. – kpg Aug 18 '16 at 08:24

2 Answers2

0

I was not able to find a solution with authentication being handled in my <signin-dialog>. What worked for me was to leave <firebase-app> and <firebase-auth> in my top-level <app> element, then fire an event from <signin-dialog> and call the <firebase-auth> signIn menthod from the evenHandler in the <app>:

<app>
<iron-ajax auto url="https://apiserver/config" handle-as="json" last-response="{{config}}"></iron-ajax>

        <template is="dom-if" if="{{config}}">
          <firebase-app auth-domain="{{config.fbWebConfig.authDomain}}" database-url="{{config.fbWebConfig.databaseURL}}" api-key="{{config.fbWebConfig.apiKey}}">
          </firebase-app>
          <firebase-auth id="auth" name='auth' user="{{user}}" on-error="handleAuthError">
          </firebase-auth>
            <signin-dialog user={{user}}></signin-dialog>
        </template>  
</app>
kpg
  • 7,644
  • 6
  • 34
  • 67
0

On your button function you can just call the following JavaScript to sign the user out of Firebase:

firebase.auth().signOut();