Skip to content

Adds a demo app to help test and facilitate Firebase Auth API development #279

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

Merged
merged 8 commits into from
Nov 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/auth/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ dist/
*~
*.swp

#Local config.
# Local config.
**/.firebaserc
demo/public/config.js
37 changes: 37 additions & 0 deletions packages/auth/buildtools/run_demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
# Copyright 2017 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Runs the server for the demo page.
#
# Usage:
# $ buildtools/run_demo.sh

# CD to the root packages/auth directory, which should be the parent directory of
# buildtools/.
cd "$(dirname $(dirname "$0"))"
# Go back to repo root and build all binaries needed for the demo app.
cd ../..
yarn prepare
# Go back to Auth package.
cd packages/auth
# Make dist directory if not already there.
mkdir -p demo/public/dist
# Copy app, auth and database binaries to demo dist directory.
cp ../firebase/firebase-app.js demo/public/dist/firebase-app.js
cp ../firebase/firebase-auth.js demo/public/dist/firebase-auth.js
cp ../firebase/firebase-database.js demo/public/dist/firebase-database.js
# Serve demo app.
cd demo
`yarn bin`/firebase serve
81 changes: 81 additions & 0 deletions packages/auth/demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Firebase-Auth for web - Auth Demo

## Prerequisite

You need to have created a Firebase Project in the
[Firebase Console](https://firebase.google.com/console/) as well as configured a web app.

## Installation
Make sure you run `yarn` to install all dependencies in the root directory.

Enable the Auth providers you would like to offer your users in the console, under
Auth > Sign-in methods.

Run:

```bash
git clone https://github.com/firebase/firebase-js-sdk.git
cd firebase-js-sdk/packages/auth/demo
```

This will clone the repository in the current directory.

If you want to be able to deploy the demo app to one of your own Firebase Hosting instance,
configure it using the following command:

```bash
firebase use --add
```

Select the project you have created in the prerequisite, and type in `default` or
any other name as the alias to use for this project.

Copy `public/sample-config.js` to `public/config.js`:

```bash
cp public/sample-config.js public/config.js
```

Then copy and paste the Web snippet config found in the console (either by clicking "Add Firebase to
your web app" button in your Project overview, or clicking the "Web setup" button in the Auth page)
in the `config.js` file.

## Deploy

### Option 1: Compile and use local Firebase Auth files

To deploy the demo app, run the following command in the root directory of Firebase Auth (use `cd ..`
first if you are still in the `demo/` folder):

```bash
yarn run demo
```

This will compile all the files needed to run Firebase Auth, and start a Firebase server locally at
[http://localhost:5000](http://localhost:5000).

### Option 2: Use CDN hosted Firebase files

If you would prefer to use a CDN instead of locally compiled Firebase Auth files, you can instead
locate the following in the `<head>` tag of `public/index.html`:

```html
<script src="dist/firebase-app.js"></script>
<script src="dist/firebase-auth.js"></script>
<script src="dist/firebase-database.js"></script>
```

Then replace that with the public CDN:

```html
<script src="https://www.gstatic.com/firebasejs/4.6.0/firebase.js"></script>
```

Finally, ensure you are in the `demo/` folder (and not the root directory of Firebase Auth package),
and run:

```bash
yarn run demo
```

This will start a Firebase server locally at [http://localhost:5000](http://localhost:5000).
13 changes: 13 additions & 0 deletions packages/auth/demo/database.rules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"rules": {
".read": "auth != null",
".write": "auth != null",
"users": {
"$user_id": {
".read": "$user_id === auth.uid",
".write": "$user_id === auth.uid"
}
}
}
}

14 changes: 14 additions & 0 deletions packages/auth/demo/firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"database": {
"rules": "database.rules.json"
},
"hosting": {
"public": "public",
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
51 changes: 51 additions & 0 deletions packages/auth/demo/public/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @fileoverview Utilities for Auth test app features.
*/


/**
* Initializes the widget for toggling reCAPTCHA size.
* @param {function(string):void} callback The callback to call when the
* size toggler is changed, which takes in the new reCAPTCHA size.
*/
function initRecaptchaToggle(callback) {
// Listen to recaptcha config togglers.
var $recaptchaConfigTogglers = $('.toggleRecaptcha');
$recaptchaConfigTogglers.click(function(e) {
// Remove currently active option.
$recaptchaConfigTogglers.removeClass('active');
// Set currently selected option.
$(this).addClass('active');
// Get the current reCAPTCHA setting label.
var size = $(e.target).text().toLowerCase();
callback(size);
});
}

// Install servicerWorker if supported.
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js', {scope: '/'})
.then(function(reg) {
// Registration worked.
console.log('Registration succeeded. Scope is ' + reg.scope);
}).catch(function(error) {
// Registration failed.
console.log('Registration failed with ' + error.message);
});
}
Loading