Skip to content

Commit 86b66c7

Browse files
committed
Add more functionality to compat layer
1 parent bc5328d commit 86b66c7

File tree

15 files changed

+162
-146
lines changed

15 files changed

+162
-146
lines changed

packages-exp/auth-compat-exp/demo/README.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Firebase-Auth for web - Auth Demo (Auth Next)
1+
# Firebase-Auth for web - Auth Demo (Auth Compatibility Layer)
22

33
## Prerequisite
44

@@ -15,7 +15,7 @@ Run:
1515

1616
```bash
1717
git clone https://github.com/firebase/firebase-js-sdk.git
18-
cd firebase-js-sdk/packages-exp/auth-exp/demo
18+
cd firebase-js-sdk/packages-exp/auth-compat-exp/demo
1919
```
2020

2121
This will clone the repository in the current directory.
@@ -30,26 +30,39 @@ firebase use --add
3030
Select the project you have created in the prerequisite, and type in `default` or
3131
any other name as the alias to use for this project.
3232

33-
Copy `src/sample-config.js` to `src/config.js`:
33+
Copy `public/sample-config.js` to `public/config.js`:
3434

3535
```bash
36-
cp src/sample-config.js src/config.js
36+
cp public/sample-config.js public/config.js
3737
```
3838

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

43+
In the `functions` folder you'll need to install the admin SDK:
44+
45+
```bash
46+
cd functions
47+
yarn install
48+
```
49+
4350
## Deploy
4451

4552
Before deploying, you may need to build the auth-exp package:
4653
```bash
4754
yarn build:deps
4855
```
4956

50-
This can take some time, and you only need to do it if you've modified the auth-exp package.
57+
You'll also need to build a fully resolved firebase-app.js and firebase-auth.js from auth-compat-exp:
58+
59+
```bash
60+
yarn build
61+
```
62+
63+
This can take some time, and you only need to do it if you've modified the auth-exp or auth-compta-exp packages.
5164

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

5467
```bash
5568
yarn run demo

packages-exp/auth-compat-exp/demo/yarn.lock

Lines changed: 3 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# yarn lockfile v1
33

44

5-
"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.8.3":
5+
"@babel/code-frame@^7.0.0":
66
version "7.10.4"
77
resolved "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.10.4.tgz#168da1a36e90da68ae8d49c0f1b48c7c6249213a"
88
integrity sha512-vG6SvB6oYEhvgisZNFRmRCUkLz11c7rp+tbNTynGqc6mS1d5ATd/sGyV6W0KZZnXRKMTzZDRgQT3Ou9jhpAfUg==
@@ -1498,11 +1498,6 @@ combined-stream@^1.0.6, combined-stream@~1.0.6:
14981498
dependencies:
14991499
delayed-stream "~1.0.0"
15001500

1501-
commander@^2.20.0:
1502-
version "2.20.3"
1503-
resolved "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
1504-
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==
1505-
15061501
15071502
version "1.1.0"
15081503
resolved "https://registry.npmjs.org/commenting/-/commenting-1.1.0.tgz#fae14345c6437b8554f30bc6aa6c1e1633033590"
@@ -2421,11 +2416,6 @@ has-flag@^3.0.0:
24212416
resolved "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
24222417
integrity sha1-tdRU3CGZriJWmfNGfloH87lVuv0=
24232418

2424-
has-flag@^4.0.0:
2425-
version "4.0.0"
2426-
resolved "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b"
2427-
integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==
2428-
24292419
has-symbols@^1.0.0, has-symbols@^1.0.1:
24302420
version "1.0.1"
24312421
resolved "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.1.tgz#9f5214758a44196c406d9bd76cebf81ec2dd31e8"
@@ -2896,14 +2886,6 @@ jest-worker@^24.0.0:
28962886
merge-stream "^2.0.0"
28972887
supports-color "^6.1.0"
28982888

2899-
jest-worker@^26.0.0:
2900-
version "26.1.0"
2901-
resolved "https://registry.npmjs.org/jest-worker/-/jest-worker-26.1.0.tgz#65d5641af74e08ccd561c240e7db61284f82f33d"
2902-
integrity sha512-Z9P5pZ6UC+kakMbNJn+tA2RdVdNX5WH1x+5UCBZ9MxIK24pjYtFt96fK+UwBTrjLYm232g1xz0L3eTh51OW+yQ==
2903-
dependencies:
2904-
merge-stream "^2.0.0"
2905-
supports-color "^7.0.0"
2906-
29072889
js-tokens@^4.0.0:
29082890
version "4.0.0"
29092891
resolved "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
@@ -4103,13 +4085,6 @@ quick-lru@^4.0.1:
41034085
resolved "https://registry.npmjs.org/quick-lru/-/quick-lru-4.0.1.tgz#5b8878f113a58217848c6482026c73e1ba57727f"
41044086
integrity sha512-ARhCpm70fzdcvNQfPoy49IaanKkTlRWF2JMzqhcJbhSFRZv7nPTvZJdcY7301IPmvW+/p0RgIWnQDLJxifsQ7g==
41054087

4106-
randombytes@^2.1.0:
4107-
version "2.1.0"
4108-
resolved "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz#df6f84372f0270dc65cdf6291349ab7a473d4f2a"
4109-
integrity sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==
4110-
dependencies:
4111-
safe-buffer "^5.1.0"
4112-
41134088
read-cmd-shim@^1.0.1:
41144089
version "1.0.5"
41154090
resolved "https://registry.npmjs.org/read-cmd-shim/-/read-cmd-shim-1.0.5.tgz#87e43eba50098ba5a32d0ceb583ab8e43b961c16"
@@ -4435,16 +4410,6 @@ [email protected]:
44354410
"@rollup/pluginutils" "^3.0.9"
44364411
source-map-resolve "^0.6.0"
44374412

4438-
4439-
version "6.1.0"
4440-
resolved "https://registry.npmjs.org/rollup-plugin-terser/-/rollup-plugin-terser-6.1.0.tgz#071866585aea104bfbb9dd1019ac523e63c81e45"
4441-
integrity sha512-4fB3M9nuoWxrwm39habpd4hvrbrde2W2GG4zEGPQg1YITNkM3Tqur5jSuXlWNzbv/2aMLJ+dZJaySc3GCD8oDw==
4442-
dependencies:
4443-
"@babel/code-frame" "^7.8.3"
4444-
jest-worker "^26.0.0"
4445-
serialize-javascript "^3.0.0"
4446-
terser "^4.7.0"
4447-
44484413
44494414
version "0.27.0"
44504415
resolved "https://registry.npmjs.org/rollup-plugin-typescript2/-/rollup-plugin-typescript2-0.27.0.tgz#95ff96f9e07d5000a9d2df4d76b548f9a1f83511"
@@ -4501,7 +4466,7 @@ rxjs@^6.4.0:
45014466
dependencies:
45024467
tslib "^1.9.0"
45034468

4504-
safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@^5.2.0, safe-buffer@~5.2.0:
4469+
safe-buffer@^5.0.1, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@^5.2.0, safe-buffer@~5.2.0:
45054470
version "5.2.1"
45064471
resolved "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6"
45074472
integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==
@@ -4538,13 +4503,6 @@ serialize-javascript@^2.1.2:
45384503
resolved "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-2.1.2.tgz#ecec53b0e0317bdc95ef76ab7074b7384785fa61"
45394504
integrity sha512-rs9OggEUF0V4jUSecXazOYsLfu7OGK2qIn3c7IPBiffz32XniEp/TX9Xmc9LQfK2nQ2QKHvZ2oygKUGU0lG4jQ==
45404505

4541-
serialize-javascript@^3.0.0:
4542-
version "3.1.0"
4543-
resolved "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-3.1.0.tgz#8bf3a9170712664ef2561b44b691eafe399214ea"
4544-
integrity sha512-JIJT1DGiWmIKhzRsG91aS6Ze4sFUrYbltlkg2onR5OrnNM02Kl/hnY/T4FN2omvyeBbQmMJv+K4cPOpGzOTFBg==
4545-
dependencies:
4546-
randombytes "^2.1.0"
4547-
45484506
set-blocking@^2.0.0, set-blocking@~2.0.0:
45494507
version "2.0.0"
45504508
resolved "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"
@@ -4671,14 +4629,6 @@ source-map-resolve@^0.6.0:
46714629
atob "^2.1.2"
46724630
decode-uri-component "^0.2.0"
46734631

4674-
source-map-support@~0.5.12:
4675-
version "0.5.19"
4676-
resolved "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
4677-
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
4678-
dependencies:
4679-
buffer-from "^1.0.0"
4680-
source-map "^0.6.0"
4681-
46824632
source-map-url@^0.4.0:
46834633
version "0.4.0"
46844634
resolved "https://registry.npmjs.org/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3"
@@ -4689,7 +4639,7 @@ source-map@^0.5.6:
46894639
resolved "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
46904640
integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=
46914641

4692-
source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.1:
4642+
source-map@^0.6.1:
46934643
version "0.6.1"
46944644
resolved "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
46954645
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
@@ -4960,13 +4910,6 @@ supports-color@^6.1.0:
49604910
dependencies:
49614911
has-flag "^3.0.0"
49624912

4963-
supports-color@^7.0.0:
4964-
version "7.1.0"
4965-
resolved "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz#68e32591df73e25ad1c4b49108a2ec507962bfd1"
4966-
integrity sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==
4967-
dependencies:
4968-
has-flag "^4.0.0"
4969-
49704913
tar@^4.4.10, tar@^4.4.12, tar@^4.4.8:
49714914
version "4.4.13"
49724915
resolved "https://registry.npmjs.org/tar/-/tar-4.4.13.tgz#43b364bc52888d555298637b10d60790254ab525"
@@ -4997,15 +4940,6 @@ temp-write@^3.4.0:
49974940
temp-dir "^1.0.0"
49984941
uuid "^3.0.1"
49994942

5000-
terser@^4.7.0:
5001-
version "4.8.0"
5002-
resolved "https://registry.npmjs.org/terser/-/terser-4.8.0.tgz#63056343d7c70bb29f3af665865a46fe03a0df17"
5003-
integrity sha512-EAPipTNeWsb/3wLPeup1tVPaXfIaU68xMnVdPafIL1TV05OhASArYyIfFvnvJCNrR2NIOvDVNNTFRa+Re2MWyw==
5004-
dependencies:
5005-
commander "^2.20.0"
5006-
source-map "~0.6.1"
5007-
source-map-support "~0.5.12"
5008-
50094943
text-extensions@^1.0.0:
50104944
version "1.9.0"
50114945
resolved "https://registry.npmjs.org/text-extensions/-/text-extensions-1.9.0.tgz#1853e45fee39c945ce6f6c36b2d659b5aabc2a26"

packages-exp/auth-compat-exp/index.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
import firebase from '@firebase/app';
19+
import * as impl from '@firebase/auth-exp/internal';
1920
import { _FirebaseNamespace } from '@firebase/app-types/private';
2021
import * as externs from '@firebase/auth-types-exp';
2122
import {
@@ -26,6 +27,8 @@ import {
2627
import '@firebase/installations';
2728
import { name, version } from './package.json';
2829
import { Auth } from './src/auth';
30+
import { RecaptchaVerifier } from './src/recaptcha_verifier';
31+
import { EmailAuthProvider } from './src/email_auth_provider';
2932

3033
const AUTH_TYPE = 'auth';
3134

@@ -53,17 +56,16 @@ function registerAuth(instance: _FirebaseNamespace): void {
5356
VERIFY_AND_CHANGE_EMAIL: externs.Operation.VERIFY_AND_CHANGE_EMAIL,
5457
VERIFY_EMAIL: externs.Operation.VERIFY_EMAIL
5558
}
56-
}
57-
// TODO(avolkovi): Expose the other top level properties
58-
// EmailAuthProvider,
59-
// FacebookAuthProvider,
60-
// GithubAuthProvider,
61-
// GoogleAuthProvider,
62-
// OAuthProvider,
59+
},
60+
EmailAuthProvider,
61+
FacebookAuthProvider: impl.FacebookAuthProvider,
62+
GithubAuthProvider: impl.GithubAuthProvider,
63+
GoogleAuthProvider: impl.GoogleAuthProvider,
64+
OAuthProvider: impl.OAuthProvider,
6365
// SAMLAuthProvider,
64-
// PhoneAuthProvider,
65-
// RecaptchaVerifier,
66-
// TwitterAuthProvider,
66+
PhoneAuthProvider: impl.PhoneAuthProvider,
67+
RecaptchaVerifier,
68+
TwitterAuthProvider: impl.TwitterAuthProvider,
6769
// Auth: {
6870
// Persistence
6971
// }
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
import firebase from '@firebase/app';
19+
import * as impl from '@firebase/auth-exp/internal';
20+
import * as compat from '@firebase/auth-types';
21+
import * as externs from '@firebase/auth-types-exp';
22+
23+
export class EmailAuthProvider implements compat.EmailAuthProvider {
24+
static readonly PROVIDER_ID = externs.ProviderId.PASSWORD;
25+
static readonly EMAIL_PASSWORD_SIGN_IN_METHOD =
26+
externs.SignInMethod.EMAIL_PASSWORD;
27+
static readonly EMAIL_LINK_SIGN_IN_METHOD = externs.SignInMethod.EMAIL_LINK;
28+
readonly providerId = EmailAuthProvider.PROVIDER_ID;
29+
30+
static credential(email: string, password: string): compat.AuthCredential {
31+
return impl.EmailAuthProvider.credential(email, password);
32+
}
33+
34+
static credentialWithLink(email: string, emailLink: string): compat.AuthCredential {
35+
return impl.EmailAuthProvider.credentialWithLink(firebase.auth!() as unknown as externs.Auth, email, emailLink);
36+
}
37+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
import firebase from '@firebase/app';
19+
import { FirebaseApp } from '@firebase/app-types';
20+
import * as impl from '@firebase/auth-exp/internal';
21+
import * as compat from '@firebase/auth-types';
22+
import * as externs from '@firebase/auth-types-exp';
23+
24+
export class RecaptchaVerifier extends impl.RecaptchaVerifier implements compat.RecaptchaVerifier {
25+
constructor(
26+
container: HTMLElement | string,
27+
parameters?: object | null,
28+
app: FirebaseApp = firebase.app()
29+
) {
30+
// API key is required for web client RPC calls.
31+
impl.assertFn(app.options?.apiKey, impl.AuthErrorCode.INVALID_API_KEY);
32+
super(container, parameters, app.auth!() as unknown as externs.Auth);
33+
}
34+
}

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
* limitations under the License.
1616
*/
1717
import resolve from '@rollup/plugin-node-resolve';
18-
import { terser } from 'rollup-plugin-terser';
1918
import strip from '@rollup/plugin-strip';
2019
import typescriptPlugin from 'rollup-plugin-typescript2';
2120
import typescript from 'typescript';
@@ -41,6 +40,7 @@ const workerPlugins = [
4140
tsconfigOverride: {
4241
compilerOptions: {
4342
declaration: false,
43+
target: "es2017",
4444
lib: [
4545
// TODO: remove this
4646
'dom',
@@ -49,11 +49,6 @@ const workerPlugins = [
4949
]
5050
}
5151
}
52-
}),
53-
terser({
54-
output: {
55-
comments: false
56-
}
5752
})
5853
];
5954

@@ -68,11 +63,6 @@ const es5Builds = [
6863
...commonPlugins,
6964
resolve({
7065
mainFields: ['module', 'main']
71-
}),
72-
terser({
73-
output: {
74-
comments: false
75-
}
7666
})
7767
]
7868
},

packages-exp/auth-exp/src/platform_browser/auth_window.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,14 @@ export type AuthWindow = {
3737
[callback: string]: (...args: unknown[]) => void;
3838
};
3939

40-
export const AUTH_WINDOW = (window as unknown) as AuthWindow;
40+
/**
41+
* Lazy accessor for window, since the compat layer won't tree shake this out,
42+
* we need to make sure not to mess with window unless we have to
43+
*/
44+
export function _window(): AuthWindow {
45+
return window as unknown as AuthWindow;
46+
}
4147

4248
export function _setWindowLocation(url: string): void {
43-
AUTH_WINDOW.location.href = url;
49+
_window().location.href = url;
4450
}

0 commit comments

Comments
 (0)