Skip to content

Commit 32bd433

Browse files
Thomas Césaré-herriauGerrit Code Review
authored andcommitted
Merge "Updated README for 0.5.0"
2 parents 5105fa5 + db9f1de commit 32bd433

File tree

5 files changed

+172
-38
lines changed

5 files changed

+172
-38
lines changed

README.md

Lines changed: 83 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,20 @@ Ionic...) nor Chrome extensions.
2727
4. [Customization](#customizing-firebaseui-for-authentication)
2828
5. [Advanced](#advanced)
2929
6. [Known issues](#known-issues)
30+
7. [Release Notes](#release-notes)
3031

3132
## Installation
3233

3334
You just need to include the following script and CSS file in the `<head>` tag of your page,
3435
below the initialization snippet from the Firebase Console:
3536

3637
```html
37-
<script src="https://www.gstatic.com/firebasejs/ui/live/0.4/firebase-ui-auth.js"></script>
38-
<link type="text/css" rel="stylesheet" href="https://www.gstatic.com/firebasejs/ui/live/0.4/firebase-ui-auth.css" />
38+
<script src="https://www.gstatic.com/firebasejs/ui/live/0.5/firebase-ui-auth.js"></script>
39+
<link type="text/css" rel="stylesheet" href="https://www.gstatic.com/firebasejs/ui/live/0.5/firebase-ui-auth.css" />
3940
```
4041

42+
You can then serve your app locally using `firebase serve`.
43+
4144
## Using FirebaseUI for Authentication
4245

4346
FirebaseUI includes the following flows:
@@ -70,11 +73,13 @@ instance should be passed to the constructor of `firebaseui.auth.AuthUI`. You ca
7073
`start` method with the CSS selector that determines where to create the widget, and a configuration
7174
object.
7275

73-
The following example shows how to set up a sign-in screen with all supported providers.
76+
The following example shows how to set up a sign-in screen with all supported providers. Please
77+
refer to the [demo application in the examples folder](examples/demo/) for a more in-depth
78+
example, showcasing a Single Page Application mode.
7479

75-
> We recommend opening the widget in a popup window or redirecting to it, as a
76-
> [known issue with single page applications](#web-single-page-applications-are-not-fully-supported)
77-
> may lead to a rendering bug.
80+
> Firebase and FirebaseUI do not work when executed directly from a file (i.e. opening the file in
81+
> your browser, not through a web server). Always run `firebase serve` (or your preferred local
82+
> server) to test your app locally.
7883
7984
```html
8085
<!DOCTYPE html>
@@ -86,8 +91,8 @@ The following example shows how to set up a sign-in screen with all supported pr
8691
* TODO(DEVELOPER): Paste the initialization snippet from:
8792
* Firebase Console > Overview > Add Firebase to your web app. *
8893
***************************************************************************************** -->
89-
<script src="https://www.gstatic.com/firebasejs/ui/live/0.4/firebase-ui-auth.js"></script>
90-
<link type="text/css" rel="stylesheet" href="https://www.gstatic.com/firebasejs/ui/live/0.4/firebase-ui-auth.css" />
94+
<script src="https://www.gstatic.com/firebasejs/ui/live/0.5/firebase-ui-auth.js"></script>
95+
<link type="text/css" rel="stylesheet" href="https://www.gstatic.com/firebasejs/ui/live/0.5/firebase-ui-auth.css" />
9196
<script type="text/javascript">
9297
// FirebaseUI config.
9398
var uiConfig = {
@@ -190,6 +195,7 @@ FirebaseUI supports the following configuration parameters.
190195
|callbacks |No |`[]` |A list of developers [callbacks](#available-callbacks) after specific events. |
191196
|queryParameterForSignInSuccessUrl|No |`"signInSuccessUrl"`|The redirect URL parameter name for the sign-in success URL. See [Overwriting the sign-in success URL](#overwriting-the-sign-in-success-url). |
192197
|queryParameterForWidgetMode |No |`"mode"` |The redirect URL parameter name for the “mode” of the Widget. See [FirebaseUI widget modes](#firebaseui-widget-modes). |
198+
|signInFlow |No |`"redirect"` |The sign-in flow to use for IDP providers: `redirect` or `popup`.
193199
|signInOptions |Yes |- |The list of [providers](#available-providers) enabled for signing into your app. The order you specify them will be the order they are displayed on the sign-in provider selection screen.|
194200
|signInSuccessUrl |No |- |The URL where to redirect the user after a successful sign-in. **Required** when the `signInSuccess` callback is not used or when it returns `true`. |
195201
|tosUrl |Yes |- |The URL of the Terms of Service page. |
@@ -204,6 +210,43 @@ FirebaseUI supports the following configuration parameters.
204210
|Github |`firebase.auth.GithubAuthProvider.PROVIDER_ID` |
205211
|Email and password|`firebase.auth.EmailAuthProvider.PROVIDER_ID` |
206212

213+
### Custom scopes
214+
215+
To specify custom scopes per provider, you can pass an object instead of just the provider value:
216+
217+
```javascript
218+
ui.start('#firebaseui-auth-container', {
219+
signInOptions = [
220+
{
221+
provider: firebase.auth.GoogleAuthProvider.PROVIDER_ID,
222+
scopes: [
223+
'https://www.googleapis.com/auth/plus.login'
224+
]
225+
},
226+
{
227+
provider: firebase.auth.FacebookAuthProvider.PROVIDER_ID,
228+
scopes: [
229+
'public_profile',
230+
'email',
231+
'user_likes',
232+
'user_friends'
233+
]
234+
},
235+
firebase.auth.TwitterAuthProvider.PROVIDER_ID, // Twitter does not support scopes.
236+
firebase.auth.EmailAuthProvider.PROVIDER_ID // Other providers don't need to be given as object.
237+
]
238+
});
239+
```
240+
241+
### Sign In Flows
242+
243+
Two sign in flows are available:
244+
245+
- `redirect`, the default, will perform a full page redirect to the sign-in page of the provider
246+
(Google, Facebook...). This is recommended for mobile apps.
247+
- The `popup` flow will open a popup to the sign-in page of the provider. If the popup is blocked by
248+
the browser, it will fall back to a full page redirect.
249+
207250
### Available callbacks
208251

209252
Currently only one callback is supported. Some will be added soon to monitor UI changes.
@@ -242,15 +285,17 @@ If the callback returns `false` or nothing, the page is not automatically redire
242285
* TODO(DEVELOPER): Paste the initialization snippet from:
243286
* Firebase Console > Overview > Add Firebase to your web app. *
244287
***************************************************************************************** -->
245-
<script src="https://www.gstatic.com/firebasejs/ui/live/0.4/firebase-ui-auth.js"></script>
246-
<link type="text/css" rel="stylesheet" href="https://www.gstatic.com/firebasejs/ui/live/0.4/firebase-ui-auth.css" />
288+
<script src="https://www.gstatic.com/firebasejs/ui/live/0.5/firebase-ui-auth.js"></script>
289+
<link type="text/css" rel="stylesheet" href="https://www.gstatic.com/firebasejs/ui/live/0.5/firebase-ui-auth.css" />
247290
<script type="text/javascript">
248291
// FirebaseUI config.
249292
var uiConfig = {
250293
// Query parameter name for mode.
251294
'queryParameterForWidgetMode': 'mode',
252295
// Query parameter name for sign in success url.
253296
'queryParameterForSignInSuccessUrl': 'signInSuccessUrl',
297+
// Will use popup for IDP Providers sign-in flow instead of the default, redirect.
298+
'signInFlow': 'popup',
254299
'signInSuccessUrl': '<url-to-redirect-to-on-success>',
255300
'signInOptions': [
256301
// Leave the lines as is for the providers you want to offer your users.
@@ -335,9 +380,33 @@ When a user has enabled the private browsing mode in Safari, the web storage is
335380
currently results in an error being thrown upon Firebase Auth initialization. Therefore, when
336381
following the snippets above, FirebaseUI will never get initialized and no UI will be displayed.
337382

338-
### Web Single Page Applications are not fully supported
383+
### Tips for Single Page apps (`UI Widget is already rendered on the page` warning)
339384

340385
When re-rendering the FirebaseUI Auth widget (for instance after signing in a user, signing her out
341-
and trying to sign her in again), it will fail with an `Uncaught Error: UI Widget is already
342-
initialized on the page. Only one widget instance can be initialized per page.` error. We recommend
343-
using the widget in a popup window or redirecting to it while we work on a fix for this issue.
386+
and trying to sign her in again), it will sometimes log a warning: `UI Widget is already rendered on
387+
the page and is pending some user interaction. Only one widget instance can be rendered per page.
388+
The previous instance has been automatically reset.`. This happens when the UI widget was in a
389+
pending state, i.e. the user was in the middle of performing a sign-in flow. You should generally
390+
avoid re-rendering the widget in the middle of an action, but if you do, to avoid the warning, you
391+
should use the `reset()` method before re-rendering the widget.
392+
393+
## Release Notes
394+
395+
### 0.5.0
396+
397+
See the milestone [0.5.0](https://github.com/firebase/firebaseui-web/milestone/1) for the issues
398+
covered in this release. Below is a summary of the most important ones:
399+
400+
- FirebaseUI now supports **Single Page Application**: a `reset` method was added to allow to
401+
dispose of the widget. When the user leaves a page where the FirebaseUI widget was rendered (for
402+
instance in the `componentWillUnmount` method of a React component), call the `reset` method of the
403+
`firebaseui.auth.AuthUI` instance you created. Also, call the `reset` method before rendering
404+
again the widget if one has already been rendered on the page. Please refer to the
405+
[demo app](examples/demo/) for guidance on how to use FirebaseUI in a Single Page
406+
Application context.
407+
- **Custom scopes** can now be added for each provider. See [Custom Scopes](custom-scopes).
408+
- Several issues, different but related to the `displayName` not being present after sign up with
409+
email and password, have been fixed.
410+
- A new config parameter has been added: `signInFlow`. It allows to specify whether the Identity
411+
Providers sign in flows should be done through `redirect` (the default) or `popup`. See
412+
[Sign In Flows](sign-in-flows).

examples/demo/database.rules.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// WARNING: This configuration is for development purpose only, as this lets
2-
// anyone read/write in your database.
1+
// No Read/Write permitted.
32
{
4-
".read": true,
5-
".write": true
3+
"rules": {
4+
".read": false,
5+
".write": false
6+
}
67
}

examples/demo/public/app.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,46 @@
1+
/**
2+
* FirebaseUI initialization to be used in a Single Page application context.
3+
*/
4+
// FirebaseUI config.
5+
var uiConfig = {
6+
'callbacks': {
7+
// Called when the user has been successfully signed in.
8+
'signInSuccess': function(user, credential, redirectUrl) {
9+
handleSignedInUser(user);
10+
// Do not redirect.
11+
return false;
12+
}
13+
},
14+
// Opens IDP Providers sign-in flow in a popup.
15+
'signInFlow': 'popup',
16+
'signInOptions': [
17+
// TODO(developer): Remove the providers you don't need for your app.
18+
{
19+
provider: firebase.auth.GoogleAuthProvider.PROVIDER_ID,
20+
scopes: ['https://www.googleapis.com/auth/plus.login']
21+
},
22+
{
23+
provider: firebase.auth.FacebookAuthProvider.PROVIDER_ID,
24+
scopes :[
25+
'public_profile',
26+
'email',
27+
'user_likes',
28+
'user_friends'
29+
]
30+
},
31+
firebase.auth.TwitterAuthProvider.PROVIDER_ID,
32+
firebase.auth.GithubAuthProvider.PROVIDER_ID,
33+
firebase.auth.EmailAuthProvider.PROVIDER_ID
34+
],
35+
// Terms of service url.
36+
'tosUrl': 'https://www.google.com'
37+
};
38+
39+
// Initialize the FirebaseUI Widget using Firebase.
40+
var ui = new firebaseui.auth.AuthUI(firebase.auth());
41+
// Keep track of the currently signed in user.
42+
var currentUid = null;
43+
144
/**
245
* Redirects to the FirebaseUI widget.
346
*/
@@ -18,6 +61,7 @@ var signInWithPopup = function() {
1861
* Displays the UI for a signed in user.
1962
*/
2063
var handleSignedInUser = function(user) {
64+
currentUid = user.uid;
2165
document.getElementById('user-signed-in').style.display = 'block';
2266
document.getElementById('user-signed-out').style.display = 'none';
2367
document.getElementById('name').textContent = user.displayName;
@@ -37,11 +81,20 @@ var handleSignedInUser = function(user) {
3781
var handleSignedOutUser = function() {
3882
document.getElementById('user-signed-in').style.display = 'none';
3983
document.getElementById('user-signed-out').style.display = 'block';
84+
ui.start('#firebaseui-container', uiConfig);
4085
};
4186

4287
// Listen to change in auth state so it displays the correct UI for when
4388
// the user is signed in or not.
4489
firebase.auth().onAuthStateChanged(function(user) {
90+
// The observer is also triggered when the user's token has expired and is
91+
// automatically refreshed. In that case, the user hasn't changed so we should
92+
// not update the UI.
93+
if (user && user.uid == currentUid) {
94+
return;
95+
}
96+
document.getElementById('loading').style.display = 'none';
97+
document.getElementById('loaded').style.display = 'block';
4598
user ? handleSignedInUser(user) : handleSignedOutUser();
4699
});
47100

examples/demo/public/index.html

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,42 @@
77

88
<!-- END OF WEB SNIPPET -->
99
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
10+
<script src="https://www.gstatic.com/firebasejs/ui/live/0.5/firebase-ui-auth.js"></script>
11+
<link type="text/css" rel="stylesheet" href="https://www.gstatic.com/firebasejs/ui/live/0.5/firebase-ui-auth.css" />
1012
<meta name="viewport" content="width=device-width, initial-scale=1">
1113
</head>
1214
<body>
1315
<div id="container">
1416
<h3>FirebaseUI Demo</h3>
15-
<div id="user-signed-in" class="hidden">
16-
<div id="user-info">
17-
<div id="photo-container">
18-
<img id="photo"></img>
17+
<div id="loading">Loading...</div>
18+
<div id="loaded" class="hidden">
19+
<div id="main">
20+
<div id="user-signed-in" class="hidden">
21+
<div id="user-info">
22+
<div id="photo-container">
23+
<img id="photo"></img>
24+
</div>
25+
<div id="name"></div>
26+
<div id="email"></div>
27+
<div class="clearfix"></div>
28+
</div>
29+
<p>
30+
<button id="sign-out">Sign Out</button>
31+
<button id="delete-account">Delete account</button>
32+
</p>
33+
</div>
34+
<div id="user-signed-out" class="hidden">
35+
<h4>You are signed out.</h4>
36+
<p>
37+
<button id="sign-in-with-redirect">Sign In with Redirect</button>
38+
<button id="sign-in-with-popup">Sign In with Popup</button>
39+
</p>
40+
<div id="firebaseui-spa">
41+
<h5>Single Page Application mode:</h5>
42+
<div id="firebaseui-container"></div>
43+
</div>
1944
</div>
20-
<div id="name"></div>
21-
<div id="email"></div>
22-
<div class="clearfix"></div>
2345
</div>
24-
<p>
25-
<button id="sign-out">Sign Out</button>
26-
<button id="delete-account">Delete account</button>
27-
</p>
28-
</div>
29-
<div id="user-signed-out" class="hidden">
30-
<h4>You are signed out.</h4>
31-
<p>
32-
<button id="sign-in-with-redirect">Sign In with Redirect</button>
33-
<button id="sign-in-with-popup">Sign In with Popup</button>
34-
</p>
3546
</div>
3647
</div>
3748
<script src="app.js"></script>

examples/demo/public/widget.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<!-- COPY AND PASTE THE WEB SETUP SNIPPET HERE: -->
77

88
<!-- END OF WEB SNIPPET -->
9-
<script src="https://www.gstatic.com/firebasejs/ui/live/0.4/firebase-ui-auth.js"></script>
10-
<link type="text/css" rel="stylesheet" href="https://www.gstatic.com/firebasejs/ui/live/0.4/firebase-ui-auth.css" />
9+
<script src="https://www.gstatic.com/firebasejs/ui/live/0.5/firebase-ui-auth.js"></script>
10+
<link type="text/css" rel="stylesheet" href="https://www.gstatic.com/firebasejs/ui/live/0.5/firebase-ui-auth.css" />
1111
<style>
1212
body {
1313
margin: 0;

0 commit comments

Comments
 (0)