Skip to content

Commit 0a0f517

Browse files
committed
Add more functionality to compat layer
1 parent bc5328d commit 0a0f517

22 files changed

+246
-168
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: 16 additions & 12 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 {
@@ -24,8 +25,11 @@ import {
2425
InstantiationMode
2526
} from '@firebase/component';
2627
import '@firebase/installations';
27-
import { name, version } from './package.json';
28+
import { 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';
32+
import { PhoneMultiFactorGenerator } from './src/phone_multi_factor_generator';
2933

3034
const AUTH_TYPE = 'auth';
3135

@@ -53,17 +57,17 @@ function registerAuth(instance: _FirebaseNamespace): void {
5357
VERIFY_AND_CHANGE_EMAIL: externs.Operation.VERIFY_AND_CHANGE_EMAIL,
5458
VERIFY_EMAIL: externs.Operation.VERIFY_EMAIL
5559
}
56-
}
57-
// TODO(avolkovi): Expose the other top level properties
58-
// EmailAuthProvider,
59-
// FacebookAuthProvider,
60-
// GithubAuthProvider,
61-
// GoogleAuthProvider,
62-
// OAuthProvider,
60+
},
61+
EmailAuthProvider,
62+
FacebookAuthProvider: impl.FacebookAuthProvider,
63+
GithubAuthProvider: impl.GithubAuthProvider,
64+
GoogleAuthProvider: impl.GoogleAuthProvider,
65+
OAuthProvider: impl.OAuthProvider,
6366
// SAMLAuthProvider,
64-
// PhoneAuthProvider,
65-
// RecaptchaVerifier,
66-
// TwitterAuthProvider,
67+
PhoneAuthProvider: impl.PhoneAuthProvider,
68+
PhoneMultiFactorGenerator,
69+
RecaptchaVerifier,
70+
TwitterAuthProvider: impl.TwitterAuthProvider,
6771
// Auth: {
6872
// Persistence
6973
// }
@@ -74,7 +78,7 @@ function registerAuth(instance: _FirebaseNamespace): void {
7478
.setMultipleInstances(false)
7579
);
7680

77-
instance.registerVersion(name, version);
81+
instance.registerVersion("auth", version);
7882
}
7983

8084
registerAuth(firebase as _FirebaseNamespace);

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class Auth extends impl.AuthImplCompat<User> implements compat.FirebaseAu
8383
email: string,
8484
password: string
8585
): Promise<compat.UserCredential> {
86-
return convertCredential(
86+
return convertCredential(this._asExtern(),
8787
impl.createUserWithEmailAndPassword(this._asExtern(), email, password)
8888
);
8989
}
@@ -104,7 +104,7 @@ export class Auth extends impl.AuthImplCompat<User> implements compat.FirebaseAu
104104
user: null
105105
};
106106
}
107-
return convertCredential(Promise.resolve(credential));
107+
return convertCredential(this._asExtern(),Promise.resolve(credential));
108108
}
109109
onAuthStateChanged(
110110
nextOrObserver: Observer<unknown> | ((a: compat.User | null) => unknown),
@@ -176,44 +176,44 @@ export class Auth extends impl.AuthImplCompat<User> implements compat.FirebaseAu
176176
return this.signInWithCredential(credential);
177177
}
178178
signInAnonymously(): Promise<compat.UserCredential> {
179-
return convertCredential(impl.signInAnonymously(this._asExtern()));
179+
return convertCredential(this._asExtern(),impl.signInAnonymously(this._asExtern()));
180180
}
181181
signInWithCredential(
182182
credential: compat.AuthCredential
183183
): Promise<compat.UserCredential> {
184-
return convertCredential(
184+
return convertCredential(this._asExtern(),
185185
impl.signInWithCredential(
186186
this._asExtern(),
187187
credential as externs.AuthCredential
188188
)
189189
);
190190
}
191191
signInWithCustomToken(token: string): Promise<compat.UserCredential> {
192-
return convertCredential(
192+
return convertCredential(this._asExtern(),
193193
impl.signInWithCustomToken(this._asExtern(), token)
194194
);
195195
}
196196
signInWithEmailAndPassword(
197197
email: string,
198198
password: string
199199
): Promise<compat.UserCredential> {
200-
return convertCredential(
200+
return convertCredential(this._asExtern(),
201201
impl.signInWithEmailAndPassword(this._asExtern(), email, password)
202202
);
203203
}
204204
signInWithEmailLink(
205205
email: string,
206206
emailLink?: string
207207
): Promise<compat.UserCredential> {
208-
return convertCredential(
208+
return convertCredential(this._asExtern(),
209209
impl.signInWithEmailLink(this._asExtern(), email, emailLink)
210210
);
211211
}
212212
signInWithPhoneNumber(
213213
phoneNumber: string,
214214
applicationVerifier: compat.ApplicationVerifier
215215
): Promise<compat.ConfirmationResult> {
216-
return convertConfirmationResult(
216+
return convertConfirmationResult(this._asExtern(),
217217
impl.signInWithPhoneNumber(
218218
this._asExtern(),
219219
phoneNumber,
@@ -224,7 +224,7 @@ export class Auth extends impl.AuthImplCompat<User> implements compat.FirebaseAu
224224
signInWithPopup(
225225
provider: compat.AuthProvider
226226
): Promise<compat.UserCredential> {
227-
return convertCredential(
227+
return convertCredential(this._asExtern(),
228228
impl.signInWithPopup(
229229
this._asExtern(),
230230
provider as externs.AuthProvider,
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
// TODO: support multiple app instances or revert this API change
36+
return impl.EmailAuthProvider.credentialWithLink(firebase.auth!() as unknown as externs.Auth, email, emailLink);
37+
}
38+
}

0 commit comments

Comments
 (0)