Skip to content

Commit 385d8ec

Browse files
committed
Web worker support for auth-next
1 parent 1c5910d commit 385d8ec

File tree

18 files changed

+5829
-109
lines changed

18 files changed

+5829
-109
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: 8 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": {
@@ -29,6 +30,7 @@
2930
"devDependencies": {
3031
"@rollup/plugin-node-resolve": "^8.0.1",
3132
"@rollup/plugin-strip": "^1.3.2",
33+
"@rollup/plugin-typescript": "0.x",
3234
"rollup": "1.32.1",
3335
"rollup-plugin-json": "4.0.0",
3436
"rollup-plugin-replace": "2.2.0",

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: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
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';
19+
import typescriptPlugin from 'rollup-plugin-typescript2';
20+
import typescript from 'typescript';
21+
2022
import pkg from './package.json';
2123

2224
const deps = Object.keys(
@@ -40,7 +42,27 @@ const es5Builds = [
4042
{
4143
input: 'src/index.js',
4244
output: [{ file: pkg.bundle, format: 'esm', sourcemap: true }],
43-
plugins: commonPlugins
45+
plugins: commonPlugins,
46+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
47+
},
48+
{
49+
input: 'src/worker/index.ts',
50+
output: [{ file: pkg.worker, format: 'esm', sourcemap: true }],
51+
plugins: [...commonPlugins,
52+
typescriptPlugin({
53+
typescript,
54+
tsconfigOverride: {
55+
compilerOptions: {
56+
lib: [
57+
"dom",
58+
"es5",
59+
"es6",
60+
"webworker"
61+
]
62+
}
63+
}
64+
})],
65+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
4466
}
4567
];
4668

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: 38 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ import {
5353
updateEmail,
5454
updatePassword,
5555
updateProfile,
56-
verifyPasswordResetCode,
57-
OAuthProvider,
58-
signInWithPopup,
59-
linkWithPopup,
60-
reauthenticateWithPopup,
61-
browserPopupRedirectResolver
56+
verifyPasswordResetCode
57+
// OAuthProvider,
58+
// signInWithPopup,
59+
// linkWithPopup,
60+
// reauthenticateWithPopup,
61+
// browserPopupRedirectResolver
6262
} from '@firebase/auth-exp';
6363

6464
import { config } from './config';
@@ -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)