Skip to content

Commit a72ccab

Browse files
authored
Web worker support for auth-next (#3413)
* Web worker support for auth-next * PR feedback * Cleanup build tree a bit
1 parent 4aa4e24 commit a72ccab

19 files changed

+5745
-125
lines changed

packages-exp/auth-exp/demo/.eslintignore

Whitespace-only changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
module.exports = {
19+
extends: '../../../config/.eslintrc.js',
20+
parserOptions: {
21+
project: 'tsconfig.json',
22+
// to make vscode-eslint work with monorepo
23+
// https://github.com/typescript-eslint/typescript-eslint/issues/251#issuecomment-463943250
24+
tsconfigRootDir: __dirname
25+
},
26+
rules: {
27+
'import/no-extraneous-dependencies': ['error', { 'devDependencies': true }]
28+
}
29+
};

packages-exp/auth-exp/demo/build.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages-exp/auth-exp/demo/package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@
44
"private": true,
55
"description": "Demo for Auth TS SDK",
66
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
7-
"bundle": "dist/bundle.js",
8-
"files": [
9-
"dist"
10-
],
7+
"bundle": "public/dist/index.js",
8+
"worker": "public/dist/web-worker.js",
119
"scripts": {
12-
"build": "sh build.sh",
13-
"demo": "sh build.sh && firebase serve",
10+
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../../.gitignore'",
11+
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../../.gitignore'",
12+
"demo": "rollup -c && firebase serve",
13+
"build": "rollup -c",
1414
"build:deps": "lerna run --scope @firebase/'{app-exp,auth-exp}' --include-dependencies build",
1515
"dev": "rollup -c -w"
1616
},
1717
"peerDependencies": {
1818
"@firebase/app-exp": "0.x",
1919
"@firebase/app-types-exp": "0.x",
20+
"@firebase/auth-exp": "0.x",
2021
"@firebase/auth-types-exp": "0.x"
2122
},
2223
"dependencies": {

packages-exp/auth-exp/demo/public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"
1010
integrity="sha256-KXn5puMvxCw+dAYznun+drMdG1IFl3agK0p/pqT9KAo= sha512-2e8qq0ETcfWRI4HJBzQiA3UoyFk6tbNyG+qSaIBZLyW9Xf3sWZHN/lxe9fTh1U45DpPf07yj94KsUHHWe4Yk1A=="
1111
crossorigin="anonymous"></script>
12-
<script src="dist/bundle.js"></script>
12+
<script src="dist/index.js"></script>
1313
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"
1414
rel="stylesheet"
1515
integrity="sha256-7s5uDGW3AHqw6xtJmNNtr+OBRJUlgkNJEo78P4b0yRw= sha512-nNo+yCHEyn0smMxSswnf/OnX6/KwJuZTlNZBjauKhTK0c+zT+q5JOCx0UFhXQ6rJR9jg6Es8gPuD2uZcYDLqSw=="

packages-exp/auth-exp/demo/rollup.config.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
1817
import resolve from '@rollup/plugin-node-resolve';
1918
import strip from '@rollup/plugin-strip';
20-
import pkg from './package.json';
19+
import typescriptPlugin from 'rollup-plugin-typescript2';
20+
import typescript from 'typescript';
2121

22-
const deps = Object.keys(
23-
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
24-
);
22+
import pkg from './package.json';
2523

2624
/**
2725
* Common plugins for all builds
@@ -41,6 +39,26 @@ const es5Builds = [
4139
input: 'src/index.js',
4240
output: [{ file: pkg.bundle, format: 'esm', sourcemap: true }],
4341
plugins: commonPlugins
42+
},
43+
{
44+
input: 'src/worker/index.ts',
45+
output: [{ file: pkg.worker, format: 'esm', sourcemap: true }],
46+
plugins: [
47+
...commonPlugins,
48+
typescriptPlugin({
49+
typescript,
50+
tsconfigOverride: {
51+
compilerOptions: {
52+
lib: [
53+
// TODO: remove this
54+
'dom',
55+
'es2015',
56+
'webworker'
57+
]
58+
}
59+
}
60+
})
61+
]
4462
}
4563
];
4664

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
export const config: object;

packages-exp/auth-exp/demo/src/index.js

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import {
5959
linkWithPopup,
6060
reauthenticateWithPopup,
6161
browserPopupRedirectResolver
62-
} from '@firebase/auth-exp';
62+
} from '@firebase/auth-exp/dist/index.browser';
6363

6464
import { config } from './config';
6565
import {
@@ -79,6 +79,7 @@ let applicationVerifier = null;
7979
let multiFactorErrorResolver = null;
8080
let selectedMultiFactorHint = null;
8181
let recaptchaSize = 'normal';
82+
let webWorker = null;
8283

8384
// The corresponding Font Awesome icons for each provider.
8485
const providersIcons = {
@@ -1565,20 +1566,27 @@ function checkDatabaseAuthAccess() {
15651566
}
15661567
}
15671568

1568-
/** Runs all web worker tests if web workers are supported. */
1569+
/**
1570+
* Runs various Firebase Auth tests in a web worker environment and confirms the
1571+
* expected behavior. This is useful for manual testing in different browsers.
1572+
* @param {string} googleIdToken The Google ID token to sign in with.
1573+
*/
15691574
function onRunWebWorkTests() {
1570-
alertNotImplemented();
1571-
// if (!webWorker) {
1572-
// alertError('Error: Web workers are not supported in the current browser!');
1573-
// return;
1574-
// }
1575-
// var onError = function(error) {
1576-
// alertError('Error code: ' + error.code + ' message: ' + error.message);
1577-
// };
1578-
// auth.signInWithPopup(new GoogleAuthProvider())
1579-
// .then(function(result) {
1580-
// runWebWorkerTests(result.credential.idToken);
1581-
// }, onError);
1575+
if (!webWorker) {
1576+
alertError('Error: Web workers are not supported in the current browser!');
1577+
return;
1578+
}
1579+
// auth.signInWithPopup(new GoogleAuthProvider()).then(
1580+
// (result) => {
1581+
webWorker.postMessage({
1582+
type: 'RUN_TESTS'
1583+
// googleIdToken: result.credential.idToken
1584+
});
1585+
// },
1586+
// error => {
1587+
// alertError('Error code: ' + error.code + ' message: ' + error.message);
1588+
// }
1589+
// );
15821590
}
15831591

15841592
/** Runs service worker tests if supported. */
@@ -1702,21 +1710,20 @@ function initApp() {
17021710

17031711
// Install servicerWorker if supported.
17041712
if ('serviceWorker' in navigator) {
1705-
navigator.serviceWorker
1706-
.register('/service-worker.js', { scope: '/' })
1707-
.then(reg => {
1708-
// Registration worked.
1709-
console.log('Registration succeeded. Scope is ' + reg.scope);
1710-
})
1711-
.catch(error => {
1712-
// Registration failed.
1713-
console.log('Registration failed with ' + error.message);
1714-
});
1713+
// navigator.serviceWorker
1714+
// .register('/service-worker.js', { scope: '/' })
1715+
// .then(reg => {
1716+
// // Registration worked.
1717+
// console.log('Registration succeeded. Scope is ' + reg.scope);
1718+
// })
1719+
// .catch(error => {
1720+
// // Registration failed.
1721+
// console.log('Registration failed with ' + error.message);
1722+
// });
17151723
}
17161724

1717-
let webWorker = null;
17181725
if (window.Worker) {
1719-
webWorker = new Worker('/web-worker.js');
1726+
webWorker = new Worker('/dist/web-worker.js');
17201727
/**
17211728
* Handles the incoming message from the web worker.
17221729
* @param {!Object} e The message event received.
@@ -1756,24 +1763,6 @@ function initApp() {
17561763
}
17571764
}
17581765

1759-
/**
1760-
* Runs various Firebase Auth tests in a web worker environment and confirms the
1761-
* expected behavior. This is useful for manual testing in different browsers.
1762-
* @param {string} googleIdToken The Google ID token to sign in with.
1763-
*/
1764-
function runWebWorkerTests(googleIdToken) {
1765-
if (webWorker) {
1766-
webWorker.postMessage({
1767-
type: 'RUN_TESTS',
1768-
googleIdToken
1769-
});
1770-
} else {
1771-
alertError(
1772-
'Error: Web workers are not supported in the current browser!'
1773-
);
1774-
}
1775-
}
1776-
17771766
// We check for redirect result to refresh user's data.
17781767
// TODO: redirect result
17791768
// auth.getRedirectResult().then(function(response) {

0 commit comments

Comments
 (0)