Skip to content

Commit ba75564

Browse files
committed
perf(behaviors): increase control on sign-in/out processes
Firstly, the `login-fire-button` is now using the new added `paper-social-button` element (by composition). The Firebase Auth element was removed from its template. The fact is when the Firebase Auth element is attached to the DOM it subscribes to Firebase and tries to log the user in when possible. Because of it, `login-fire` elements lose control on the sign-in/sign-out process progression and can't inform the user in real time. To solve it, I introduced a new property `auto`. When this property is `false` the Firebase Auth is not created and not attached to the DOM without user action (form validation, social button click). It introduces another minor side effect which is `login-fire` elements that do not have the `auto` property to `true` are not sync with those who have it till the user has interaction with them. Secondly, now the elements use the user representation stored by Firebase Auth. It means the local representation is always prioritized over the network. As you can imagine, you get instant connection. Thirdly, the events firing system was also improved. Now it uses an observer that ensure to fire events at the last time, after all others properties are up to date. For example, it avoids to accidently ignore a signIn/signOut call because the progress state is not yet updated or get the previous user representation when we are listening on the "signedin" and "signedout" events. Finally, unit test suites were added. To be honest, without unit tests and integration tests I'm not able to really know how much I have potentially broke the elements, especially with the low frequency I work on this project. I expect you have issue with rendering if you have fix some locally by adding some CSS rules (because the apper-social-button fixes some CSS issues by itself). And I guess you have automatic connection that is not the default behavior here. We can discuss about the to turn the default value of `auto` property to `true`. Until then, you have to add `auto` attribute on all your login-fire elements. BREAKING CHANGE: The `signedin` event does not contain the user's credential anymore. `login-fire` elements do not automatically try to log the user in (see `auto` property). Related: #165, #51, #149, #131
1 parent f964104 commit ba75564

6 files changed

+224
-319
lines changed

login-fire-button.html

Lines changed: 24 additions & 217 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@
55
LICENSE file or at https://github.com/convoo/login-fire/blob/master/LICENSE.
66
-->
77
<link rel="import" href="../polymer/polymer.html">
8+
<link rel="import" href="./paper-social-button.html">
89
<link rel="import" href="./login-fire-social-behavior.html">
9-
<link rel="import" href="../polymerfire/firebase-auth.html">
10-
<link rel="import" href="../paper-button/paper-button.html">
11-
<link rel="import" href="./login-fire-styles.html">
12-
<link rel="import" href="../iron-icon/iron-icon.html">
13-
<link rel="import" href="./icons.html">
14-
<link rel="import" href="../paper-progress/paper-progress.html">
10+
<link rel="import" href="./localize-behavior.html">
1511

1612
<!--
1713
A button to authenticate a user with a federated identity provider such as Google, Facebook, Twitter or GitHub.
@@ -38,126 +34,37 @@
3834
3935
### Styling
4036
41-
Style the buttons with CSS as you would a normal DOM element. The following
42-
custom properties and mixins are available:
43-
44-
| Custom property | Description | Default
45-
| -- | -- | --
46-
| `--login-fire-button` | Mixin applied on the button | `{}`
47-
| `--login-fire-button-anonymous` | Mixin applied on the anonymous button | `{}`
48-
| `--login-fire-button-anonymous-hover` | Mixin applied on the anonymous button when mouve hovers it | `{}`
49-
| `--login-fire-button-facebook` | Mixin applied on the Facebook button | `{}`
50-
| `--login-fire-button-facebook-hover` | Mixin applied on the Facebook button when mouve hovers it | `{}`
51-
| `--login-fire-button-github` | Mixin applied on the GitHub button | `{}`
52-
| `--login-fire-button-github-hover` | Mixin applied on the GitHub button when mouve hovers it | `{}`
53-
| `--login-fire-button-google` | Mixin applied on the Google button | `{}`
54-
| `--login-fire-button-google-hover` | Mixin applied on the Google button when mouve hovers it | `{}`
55-
| `--login-fire-button-icon` | Mixin applied on the icon of the button | `{}`
56-
| `--login-fire-button-text` | Mixin applied on the text of the button | `{}`
57-
| `--login-fire-button-twitter` | Mixin applied on the Twitter button | `{}`
58-
| `--login-fire-button-twitter-hover` | Mixin applied on the Twitter button when mouve hovers it | `{}`
59-
| `--login-fire-btn-signout` | Mixin applied to the sign-out button | `{}`
60-
| `--login-fire-btn-signout-hover` | Mixin applied to the sign-out button when mouve hovers it | `{}`
61-
| `--login-fire-progress-active-color` | The color that is applied to the paper-progress bar as active color | `--google-green-500`
62-
| `--login-fire-progress-container-color` | The color that is applied to the paper-progress-container | `--google-grey-300`
37+
See the "Styling" section of the `paper-social-button` element documentation.
6338
6439
@customElement
6540
@polymer
6641
@demo demo/login-fire-button.html
6742
-->
6843
<dom-module id="login-fire-button">
6944
<template>
70-
<style include="login-fire-styles">
71-
:host {
72-
display: inline-block;
73-
@apply --login-fire-button;
74-
}
75-
.btn {
76-
text-align: left;
77-
text-transform: none;
78-
min-height: 40px;
79-
display: flex;
80-
@apply --login-fire-button;
81-
}
82-
.btn--google{
83-
@apply --login-fire-button-google;
84-
}
85-
.btn--google:hover{
86-
@apply --login-fire-button-google-hover;
87-
}
88-
.btn--twitter{
89-
@apply --login-fire-button-twitter;
90-
}
91-
.btn--twitter:hover{
92-
@apply --login-fire-button-twitter-hover;
93-
}
94-
.btn--facebook{
95-
@apply --login-fire-button-facebook;
96-
}
97-
.btn--facebook:hover{
98-
@apply --login-fire-button-facebook-hover;
99-
}
100-
.btn--github{
101-
@apply --login-fire-button-github;
102-
}
103-
.btn--github:hover{
104-
@apply --login-fire-button-github-hover;
105-
}
106-
.btn--anonymous{
107-
@apply --login-fire-button-anonymous;
108-
}
109-
.btn--anonymous:hover{
110-
@apply --login-fire-button-anonymous-hover;
111-
}
112-
.btn__icon {
113-
padding-left: 8px;
114-
width: 30px;
115-
height: 16px;
116-
@apply --login-fire-button-icon;
117-
}
118-
.btn__text {
119-
text-align: center;
120-
width: 100%;
121-
@apply --login-fire-button-text;
122-
}
123-
.btn__signed-out{
124-
background-color: transparent;
125-
color: grey;
126-
text-align: center;
127-
width: 170px;
128-
@apply --login-fire-btn-signout;
129-
}
130-
131-
.btn__signed-out:hover {
132-
background-color: lightgray;
133-
@apply --login-fire-btn-signout-hover;
134-
}
135-
136-
[hidden] {
137-
display: none !important;
138-
}
139-
</style>
140-
141-
<paper-button class$="btn btn--[[provider]] [[_miniClass]] [[_signOutClass]]" raised$="[[!flat]]" disabled$="[[inProgress]]">
142-
<iron-icon class="btn__icon" icon="login-fire-icons:[[provider]]" hidden$="[[_hideIcon]]"></iron-icon>
143-
<iron-icon class="btn__icon" icon="login-fire-icons:logout" hidden$="[[!_hideIcon]]"></iron-icon>
144-
<span class="btn__text">[[_text]]</span>
145-
<paper-progress class="btn-progress" hidden$="[[!inProgress]]" disabled$="[[!inProgress]]" indeterminate></paper-progress>
146-
</paper-button>
147-
148-
<firebase-auth id="auth"
149-
app-name="[[appName]]"
150-
provider="[[provider]]"
151-
user="{{_user}}"
152-
status-known="{{_statusKnown}}"
153-
signed-in="{{_signedIn}}">
154-
</firebase-auth>
45+
<paper-social-button
46+
provider="[[config.provider]]"
47+
no-sign-in="[[noSignIn]]"
48+
no-sign-out="[[noSignOut]]"
49+
language="[[language]]"
50+
show-sign-out$="[[_signedIn]]"
51+
show-sign-up$="[[showSignUp]]"
52+
show-progress-bar$="[[inProgress]]"
53+
flat$="[[flat]]"
54+
mini$="[[mini]]"
55+
disabled$="[[inProgress]]"
56+
on-tap="signInOrOut">
57+
</paper-social-button>
15558
</template>
15659

15760
<script>
15861
Polymer({
15962
is: 'login-fire-button',
160-
behaviors: [Convoo.LoginFireSocialBehavior],
63+
64+
behaviors: [
65+
Convoo.LocalizeBehavior,
66+
Convoo.LoginFireSocialBehavior
67+
],
16168

16269
properties: {
16370
/**
@@ -171,113 +78,13 @@
17178
},
17279

17380
/**
174-
* Defines if the provider icon must be hidden or not.
81+
* Flat button, yes or not.
17582
*
17683
* @type {Boolean}
17784
*/
178-
_hideIcon: {
85+
flat: {
17986
type: Boolean,
180-
computed: '_computeHideIcon(noSignIn, noSignOut, signedIn)'
181-
},
182-
183-
/**
184-
* CSS class added when the button has mini format.
185-
*
186-
* @type {String}
187-
*/
188-
_miniClass: {
189-
type: String,
190-
computed: '_computeMiniClass(mini)'
191-
},
192-
193-
/**
194-
* CSS class added when the log-out button is shown.
195-
*
196-
* @type {String}
197-
*/
198-
_signOutClass: {
199-
type: String,
200-
computed: '_computeSignOutClass(noSignIn, noSignOut, signedIn)'
201-
},
202-
203-
/**
204-
* Button text.
205-
*
206-
* @type {String}
207-
*/
208-
_text: {
209-
type: String,
210-
computed: '_computeButtonText(config.provider, showSignUp, noSignIn, noSignOut, signedIn, localize, language)'
211-
}
212-
},
213-
214-
listeners: {
215-
'click': 'signInOrOut'
216-
},
217-
218-
/**
219-
* The provider logo is shown when the user can sign in and is not yet signed
220-
* in or when they can not sign out. It is hidden otherwise.
221-
*
222-
* @param {Boolean} noSignIn is `false` if a user can sign in
223-
* @param {Boolean} noSignOut is `false` if the element can sign out
224-
* @param {Boolean} signedIn is `true` if a user is actually signed in
225-
* @return {Boolean} `true` if the element can sign out and a
226-
* user is currently signed in.
227-
*/
228-
_computeHideIcon: function(noSignIn, noSignOut, signedIn) {
229-
return !((!noSignIn && !signedIn) || noSignOut);
230-
},
231-
232-
/**
233-
* Computes the CSS class to add according to the mini format of the
234-
* element.
235-
*
236-
* @param {Boolean} isMini `true` if the button is in mini format
237-
* @return {String} a CSS class name to add when `isMini` is true,
238-
* else returns an empty string.
239-
*/
240-
_computeMiniClass: function(isMini) {
241-
return isMini ? 'btn--mini' : '';
242-
},
243-
244-
/**
245-
* Computes the CSS class to add when the user is currently signed in.
246-
*
247-
* @param {Boolean} noSignOut is `false` if the element can sign out
248-
* @param {Boolean} signedIn is `true` if a user is actually signed in
249-
* @return {String} a CSS class name to add when element can sign out
250-
*/
251-
_computeSignOutClass: function(noSignIn, noSignOut, signedIn) {
252-
if (noSignIn || (!noSignOut && signedIn)) {
253-
return 'btn__signed-out';
254-
}
255-
},
256-
257-
/**
258-
* Computes the text to be displayed inside the button.
259-
*
260-
* @param {Object} user logged-in
261-
* @param {Object} provider used for the authentication
262-
* @return {String} the text to be displayed inside the button.
263-
*/
264-
_computeButtonText: function(provider, showSignUp, noSignIn, noSignOut, signedIn, localize, language) {
265-
// User logged in.
266-
if (noSignIn || (!noSignOut && signedIn) || !provider) {
267-
return localize('lf-signout');
268-
}
269-
270-
// User not logged in and mini format.
271-
if (this.mini) {
272-
return provider.name;
273-
}
274-
275-
if (showSignUp && !noSignIn) {
276-
// User doesn't have account
277-
return localize('lf-signup-' + provider.id);
278-
} else if (!noSignIn) {
279-
// User has account
280-
return localize('lf-signin-' + provider.id);
87+
value: false
28188
}
28289
}
28390
});

0 commit comments

Comments
 (0)