Skip to content

Commit 82b7bae

Browse files
committed
Add more functionality to compat layer
1 parent bc5328d commit 82b7bae

33 files changed

+944
-777
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/functions/index.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2018 Google Inc.
3+
* Copyright 2018 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -30,14 +30,16 @@ exports.checkIfAuthenticated = functions.https.onRequest((req, res) => {
3030
const idToken = req.get('x-id-token');
3131
res.setHeader('Content-Type', 'application/json');
3232
if (idToken) {
33-
admin.auth().verifyIdToken(idToken)
34-
.then((decodedIdToken) => {
35-
res.status(200).send(JSON.stringify({uid: decodedIdToken.sub}));
36-
})
37-
.catch((error) => {
38-
res.status(400).send(JSON.stringify({error: error.code}));
39-
});
33+
admin
34+
.auth()
35+
.verifyIdToken(idToken)
36+
.then(decodedIdToken => {
37+
res.status(200).send(JSON.stringify({ uid: decodedIdToken.sub }));
38+
})
39+
.catch(error => {
40+
res.status(400).send(JSON.stringify({ error: error.code }));
41+
});
4042
} else {
41-
res.status(403).send(JSON.stringify({error: 'Unauthorized access'}));
43+
res.status(403).send(JSON.stringify({ error: 'Unauthorized access' }));
4244
}
4345
});

packages-exp/auth-compat-exp/demo/public/common.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2017 Google Inc.
3+
* Copyright 2017 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@
1919
* @fileoverview Utilities for Auth test app features.
2020
*/
2121

22-
2322
/**
2423
* Initializes the widget for toggling reCAPTCHA size.
2524
* @param {function(string):void} callback The callback to call when the
@@ -34,21 +33,25 @@ function initRecaptchaToggle(callback) {
3433
// Set currently selected option.
3534
$(this).addClass('active');
3635
// Get the current reCAPTCHA setting label.
37-
var size = $(e.target).text().toLowerCase();
36+
var size = $(e.target)
37+
.text()
38+
.toLowerCase();
3839
callback(size);
3940
});
4041
}
4142

4243
// Install servicerWorker if supported.
4344
if ('serviceWorker' in navigator) {
44-
navigator.serviceWorker.register('/service-worker.js', {scope: '/'})
45-
.then(function(reg) {
46-
// Registration worked.
47-
console.log('Registration succeeded. Scope is ' + reg.scope);
48-
}).catch(function(error) {
49-
// Registration failed.
50-
console.log('Registration failed with ' + error.message);
51-
});
45+
navigator.serviceWorker
46+
.register('/service-worker.js', { scope: '/' })
47+
.then(function(reg) {
48+
// Registration worked.
49+
console.log('Registration succeeded. Scope is ' + reg.scope);
50+
})
51+
.catch(function(error) {
52+
// Registration failed.
53+
console.log('Registration failed with ' + error.message);
54+
});
5255
}
5356

5457
var webWorker = null;
@@ -59,11 +62,12 @@ if (window.Worker) {
5962
* @param {!Object} e The message event received.
6063
*/
6164
webWorker.onmessage = function(e) {
62-
console.log('User data passed through web worker: ', e.data);
65+
console.log('User data passed through web worker: ', e.data);
6366
switch (e.data.type) {
6467
case 'GET_USER_INFO':
6568
alertSuccess(
66-
'User data passed through web worker: ' + JSON.stringify(e.data));
69+
'User data passed through web worker: ' + JSON.stringify(e.data)
70+
);
6771
break;
6872
case 'RUN_TESTS':
6973
if (e.data.status == 'success') {
@@ -84,7 +88,7 @@ if (window.Worker) {
8488
*/
8589
function onGetCurrentUserDataFromWebWorker() {
8690
if (webWorker) {
87-
webWorker.postMessage({type: 'GET_USER_INFO'});
91+
webWorker.postMessage({ type: 'GET_USER_INFO' });
8892
} else {
8993
alertError('Error: Web workers are not supported in the current browser!');
9094
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* @license
3-
* Copyright 2017 Google Inc. All Rights Reserved.
3+
* Copyright 2017 Google LLC All Rights Reserved.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
66
* in compliance with the License. You may obtain a copy of the License at
@@ -14,10 +14,10 @@
1414
*/
1515

1616
var config = {
17-
apiKey: "YOUR_API_KEY",
18-
authDomain: "your-app.firebaseapp.com",
19-
databaseURL: "https://your-app.firebaseio.com",
20-
projectId: "your-app",
21-
storageBucket: "your-app.appspot.com",
22-
messagingSenderId: "MESSAGING_SENDER_ID"
17+
apiKey: 'YOUR_API_KEY',
18+
authDomain: 'your-app.firebaseapp.com',
19+
databaseURL: 'https://your-app.firebaseio.com',
20+
projectId: 'your-app',
21+
storageBucket: 'your-app.appspot.com',
22+
messagingSenderId: 'MESSAGING_SENDER_ID'
2323
};

0 commit comments

Comments
 (0)