Skip to content

Copy demo code over to auth-compat-layer, fix our build scripts #3563

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 4 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
Empty file.
29 changes: 29 additions & 0 deletions packages-exp/auth-compat-exp/demo/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @license
* Copyright 2020 Google LLC
*
* 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.
*/

module.exports = {
extends: '../../../config/.eslintrc.js',
parserOptions: {
project: 'tsconfig.json',
// to make vscode-eslint work with monorepo
// https://github.com/typescript-eslint/typescript-eslint/issues/251#issuecomment-463943250
tsconfigRootDir: __dirname
},
rules: {
'import/no-extraneous-dependencies': ['error', { 'devDependencies': true }]
}
};
5 changes: 5 additions & 0 deletions packages-exp/auth-compat-exp/demo/.firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"avolkovi-auth": "avolkovi-auth"
}
}
6 changes: 6 additions & 0 deletions packages-exp/auth-compat-exp/demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
src/config.js
.firebaserc
public/config.js
public/service-worker.*
public/web-worker.*
public/index.*
73 changes: 73 additions & 0 deletions packages-exp/auth-compat-exp/demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Firebase-Auth for web - Auth Demo (Auth Compatibility Layer)

## 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-exp/auth-compat-exp/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.

In the `functions` folder you'll need to install the admin SDK:

```bash
cd functions
yarn install
```

## Deploy

Before deploying, you may need to build the auth-exp package:
```bash
yarn build:deps
```

You'll also need to build a fully resolved firebase-app.js and firebase-auth.js from auth-compat-exp:

```bash
yarn build
```

This can take some time, and you only need to do it if you've modified the auth-exp or auth-compta-exp packages.

To run the app locally, simply issue the following command in the `auth-compat-exp/demo` directory:

```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).

13 changes: 13 additions & 0 deletions packages-exp/auth-compat-exp/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-exp/auth-compat-exp/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": "/checkIfAuthenticated",
"function": "checkIfAuthenticated"
}
]
}
}
45 changes: 45 additions & 0 deletions packages-exp/auth-compat-exp/demo/functions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @license
* Copyright 2018 Google LLC
*
* 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 Defines the HTTP endpoints hosted via firebase functions which
* are used to test service worker functionality for Firebase Auth via demo
* app.
*/

const functions = require('firebase-functions');
const admin = require('firebase-admin');

admin.initializeApp(functions.config().firebase);

exports.checkIfAuthenticated = functions.https.onRequest((req, res) => {
const idToken = req.get('x-id-token');
res.setHeader('Content-Type', 'application/json');
if (idToken) {
admin
.auth()
.verifyIdToken(idToken)
.then(decodedIdToken => {
res.status(200).send(JSON.stringify({ uid: decodedIdToken.sub }));
})
.catch(error => {
res.status(400).send(JSON.stringify({ error: error.code }));
});
} else {
res.status(403).send(JSON.stringify({ error: 'Unauthorized access' }));
}
});
16 changes: 16 additions & 0 deletions packages-exp/auth-compat-exp/demo/functions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase serve --only functions",
"shell": "firebase experimental:functions:shell",
"start": "yarn shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"firebase-admin": "8.11.0",
"firebase-functions": "3.6.1"
},
"private": true
}
Loading