Skip to content

Commit a831aec

Browse files
sam-gcavolkoviFeiyang1scottcrossen
authored
Merge auth-exp into master (#3722)
* Initial submit of auth-next framework (#2851) Initial package structure--copied from packages/template, but with tests working * Add mock fetch helper (#2878) Add mock fetch library for tests * Add core types & error map to auth-exp (#2890) * Add core types & error map * [AUTOMATED]: Prettier Code Styling * [AUTOMATED]: License Headers * User should be an interface for now we can make an implementation class later * Add signUp API method for auth-next (#2892) * User should be an interface for now we can make an implementation class later * Add API call to signUp * [AUTOMATED]: Prettier Code Styling * [AUTOMATED]: License Headers * Update tests to test a little more * [AUTOMATED]: Prettier Code Styling * Add initial user object implementation (#2896) * Initial user object implementation * Consolidate mock auth object, add user object (#2906) * Consolidate mock auth / add user test helper * [AUTOMATED]: Prettier Code Styling * Fix tests * Add remaining API methods to auth-next (#2901) * User should be an interface for now we can make an implementation class later * Add API call to signUp * [AUTOMATED]: Prettier Code Styling * Update tests to test a little more * Add remaining API methods to auth-next * [AUTOMATED]: Prettier Code Styling * [AUTOMATED]: License Headers * Add more tests to account API methods * Pass in SDK version & correctly send GET request params * [AUTOMATED]: Prettier Code Styling * [AUTOMATED]: Prettier Code Styling * Fix import ordering * Minor formatting change * [AUTOMATED]: Prettier Code Styling * Add support for API timeouts to auth-next (#2915) * Add support for API timeouts to auth-next * PR feedback * [AUTOMATED]: Prettier Code Styling * Add version helpers to auth-next (#2910) * Add version helper to auth-next * [AUTOMATED]: Prettier Code Styling * PR feedback * Add persistence layer: index db, in memory, and browser{local, session} (#2908) * Add fetchSignInMethodsForEmail to auth-next (#2924) * Add fetchSignInMethodsForEmail to auth-next * [AUTOMATED]: Prettier Code Styling * PR Feedback * [AUTOMATED]: Prettier Code Styling * Add sendEmailVerification to auth-next (#2926) * Add sendEmailVerification to auth-next * [AUTOMATED]: Prettier Code Styling * Add missing test * Remove GetOobCodeRequestType in favor of Operation * Add a persistence manager class (#2925) * Added react native build target (#2947) * Add password reset methods to auth-next (#2928) * Add sendEmailVerification to auth-next * [AUTOMATED]: Prettier Code Styling * Remove GetOobCodeRequestType in favor of Operation * Add password reset methods to auth-next * [AUTOMATED]: Prettier Code Styling * PR Feedback * [AUTOMATED]: Prettier Code Styling * [AUTOMATED]: Prettier Code Styling * Resolve merge conflicts * [AUTOMATED]: Prettier Code Styling * use queryString helper in auth-next (#2936) * Use queryString from firebase/util instead of homebrew one * [AUTOMATED]: Prettier Code Styling * PR Feedback * [AUTOMATED]: Prettier Code Styling * Initial auth object implementation + initializeAuth() (#2932) * use app-exp in the build:deps script * Add conditional delays to auth-next (#2934) * Add conditional delays to auth-next * [AUTOMATED]: Prettier Code Styling * Use typescript asserts keyword for typesafe assertions * [AUTOMATED]: Prettier Code Styling * Rebase conflicts & PR feedback * More PR Feedback * Strip debug asserts from prod builds * [AUTOMATED]: Prettier Code Styling * [AUTOMATED]: API Reports * Fix logic in assertion * Revert merge artifacts * PR Feedback * Add sendSignInWithEmail to auth-next (#2960) * Add sendSignInWithEmail links * [AUTOMATED]: Prettier Code Styling * PR Feedback * PR Feedback * Add auth listener implementation, add user.reload() (#2961) * Standardize auth-next style (#2983) * Standardize auth-next style - prefix directory for test blocks - use kebab style for test values to make them visually distinct from keys - use '#' to prefix instance methods and '.' for class methods - prefix all private exported methods with '_' * [AUTOMATED]: Prettier Code Styling * Two more cases I missed * Add refresh token endpoint + implementation to token manager (#2975) * Add react native persistence class (#2955) Added React Native persistence class * Add getIdTokenResult implementation (#3014) * Update internal types to work with external types (#3075) * Update internal types to work with external types * [AUTOMATED]: Prettier Code Styling * [AUTOMATED]: License Headers * PR feedback * [AUTOMATED]: Prettier Code Styling * Further refactoring of auth types. Add public exports to src/index.ts (#3078) * Further refactoring of auth types. Add public exports to src/index.ts * Add app-exp to devDependencies * PR feedback * user.delete() implementation (#3072) * user.delete() implementation * [AUTOMATED]: Prettier Code Styling * PR feedback * PR feedback * Use auth impl object instead of mock auth object (#3098) * Add signInWithCredential to auth-next (#2963) * Add signInWithCredential to auth-next * [AUTOMATED]: Prettier Code Styling * Add conditional delays to auth-next (#2934) * Add conditional delays to auth-next * [AUTOMATED]: Prettier Code Styling * Use typescript asserts keyword for typesafe assertions * [AUTOMATED]: Prettier Code Styling * Rebase conflicts & PR feedback * More PR Feedback * Strip debug asserts from prod builds * [AUTOMATED]: Prettier Code Styling * [AUTOMATED]: API Reports * Fix logic in assertion * Revert merge artifacts * PR Feedback * Cleanup & PR Feedback * [AUTOMATED]: Prettier Code Styling * [AUTOMATED]: License Headers * Add more tests * [AUTOMATED]: Prettier Code Styling * Rebase conflicts * Cleanup type exports * PR feedback * Declare abstract class abstractly * Refactor so every unit test gets its own Auth object (#3129) * Refactor so every unit test gets its own Auth object * PR feedback * Formatting * Add updateProfile, updateEmail, updatePassword (#3122) * Profile management * Add updateProfile, updateEmail, updatePassword * Fixing up tests * Update tests further * Add re-exports for public functions * Fix up authCredential types to use public versions * Formatting * Code cleanup * Formatting * PR feedback * Formatting * Add recaptcha implementation (#3166) * Add recaptcha * Formatting * Export in index.ts * Address PR feedback, add a test helper for stubbing timeouts * Formatting * Add signInWithPhoneNumber implementation (#3191) * Add signInWithPhoneNumber flow * Formatting * PR feedback * Formatting * Add signInAnonymously to auth-next (#2986) * Add signInWithCredential to auth-next * Add signInAnonymously to auth-next * [AUTOMATED]: Prettier Code Styling * Add more tests * Move these back into providers * One more rebase * Add signInWithCustomToken implementation (#3136) * Add signInWithCustomToken * Add re-export in index.ts * Formatting * Formatting * add signInWithEmailAndPassword & signInWithEmailLink to auth-next (#3209) * Cleanup credential inheritance tree * Add signInWithEmailAndPassword and signInWithEmailLink to auth-next * j/k phone credential/provider are actually public * Add tests * PR feedback * Add linkWithCredential(), linkWithPhoneNumber(), unlink() (#3213) * Add unlink(), linkWithCredential(), linkWithPhoneNumber() * Formatting * Formatting * PR feedback * Formatting * Add export to index.ts * Formatting * Add createUserWithEmailAndPassword to auth-next (#3212) * Add createUserWithEmailAndPassword to auth-next * PR feedback * Cleanup public types in auth-next (#3217) * Cleanup public types in auth-next * PR feedback * Add a demo page to auth-exp using the new modular methods (#3197) * Add basic demo for new SDK * Formatting * Add anonymous auth and custom token * Formatting * Update to include newly-implemented pieces * Formatting * Add custom email flow methods to auth-next (#3223) * Add reauthenticateWithCredential, reauthenticateWithPhoneNumber (#3225) * Add link and reauth implementation to email credential (#3226) * Add linking and reauth to email credential * Formatting * Add tests for new api method * Formatting * Add AdditionalUserInfo class to auth-exp (#2979) Add AdditionalUserInfo * Big refactor of reauth / link + basic idp tasks (#3242) * Big refactor of reauth / link + basic idp tasks * PR feedback * Formatting * Add useDeviceLanguage to auth-next (#3273) * Fix broken build (#3275) * Fix some stuff * Formatting * fixed scott's broken test cases. Stupid scott Co-authored-by: Scott Crossen <[email protected]> * Address (some) of the tree shaking issues w/ ReCaptcha (#3277) * Address (some) of the recaptcha tree-shaking issues * Formatting * Add gapi and iframe loading libraries (#3334) * Add popup util and bare-bones OAuthProvider (#3335) * First pass at adding MFA support to auth-next (#3292) * First pass at adding MFA support to auth-next * Refactor IDP & reauth interfaces a bit to play nicer with MFA * PR feedback * More tests & interface cleanup * One last test * More PR Feedbakc * Tree shakeable persistence (#3288) * Make the persistence objects tree-shakeable * Formatting * Updated to stop using casts everywhere * Formatting * Make the browser impls tree shakeable * Formatting * Fix the react native implementation in auth-compat-exp * Formatting * Make the react native class wrapped in a closure, to avoid the prototype nonsense * Formatting * Fix index.rn.ts * Formatting * PR feedback * Fix ordering in index.ts * Formatting * Fix test * Formatting * Make the _getInstance() instantiator a util for the whole SDK (#3369) * Make the _getInstance() instantiator a util for the whole SDK * PR feedback, added some debugAsserts * Formatting * Add browser popup resolver class, some utils (#3336) * Add auth event manager and popup_redirect browser implementation * Add browser popup implementation, some utils * Formatting * PR feedback * Formatting * Fix failing tests * formatting * Merge conflict * Cleanup demo code & get it working with MFA flows (#3380) - lint the demo - fix some error handling code - fix verifyPhoneNumber when called with MFA context - add to/fromJSON to EmailAuthCredential * Add updatePhoneNumber to auth-next (#3392) * Add verifyBeforeUpdate to auth-next (#3391) * Add verifyBeforeUpdate to auth-next Also add a couple edge cases that I missed first pass around * Export verifyBeforeUpdateEmail * Add popup strategy implementation, (sign in, link, reauth) (#3363) * Popup strategy implementation * Popup strategy + tests * Formatting * Updated comment * Fix IdpTask types * Refactor popup code to have abstract base * WIP * Early feedback * Feedback, tests * Formatting * Formatting * Formatting * Update the auth event manager to handle redirects. Add redirect logic to popupredirectresolver (#3409) * Update event manager and abstract popup redirect operation to handle redirect events * Missing popup_redirect update * Tests * Formatting * PR feedback * Formatting * Populate enrolled factors on reload() (#3406) * Add persistence for redirect users (#3410) * Updates to auth for persistence redirect user * Add tests for persistence * Formatting * Removing erroneous console.logs * Formatting * Updates to the auth init flow * Formatting * Fix typo * Formatting * Rogue console.logwq * Formatting * PR feedback * Formatting * Web worker support for auth-next (#3413) * Web worker support for auth-next * PR feedback * Cleanup build tree a bit * Add redirect strategy (#3416) * Redirect strategy * Redirect strategy updates & test * Formatting * Moving the ts files in demo/ to 'broken' since they cause 'yarn test' to break and Alex is unavailable this week * Add auth isolation for oauth flows (#3420) * Add auth isolation for oauth flows * Formatting * Fix bug * Formatting * PR feedback * Formatting * Move all of our helper files in test/ to a new directory test/helpers/ (#3452) * Move all of our helper files in test/ to a new directory test/helpers/ * Formatting * Foundation for integration tests for auth-exp (#3453) * Add integration test foundation * Formatting * Update to use a describe wrapper instead * Formatting * PR feedback * Removed custom describe * Formatting * Add integration tests for anonymous auth (#3455) * added a suite of anonymous auth integration tests * Updated to use new structure * Formatting * PR feedback * Formatting * Update the integration testing structure to have a new auth every test (#3457) * Fix integration tests to not be so clever * Formatting * Add integration tests for email flow (#3462) * Add email integration tests * Formatting * PR feedback * Formatting * Add integration tests for phone, plus address some issues caught by them (#3478) * Phone integration tests (plus some bugs that it caught) * Formatting * PR feedback * Formatting * Refactor the way UserCredentials work in anticipation of mudularization (#3489) * Refactor the way UserCredentials work in anticipation of mudularization * Formatting * PR feedback * Linter fixes * Formatting * First pass at service workers for auth-next (#3434) * Fix broken integration tests (#3503) * Add a standard OAuthCredential and a GoogleAuthProvider (#3498) * Add a standard OAuthCredential and a GoogleAuthProvider * Formatting * Signature updates * Formatting * Update w/ demo * PR feedback plus a bugfix * Formatting * Add the remaining oauth providers (#3500) * Add the rest of the OAuth providers * Formatting * Add to demo * Handle some edge cases in responses from the server (#3509) * Add error handling for account-exists-with-different-credentials edgecase * Tests * Formatting * First pass at polyfill (#3517) * First pass at polyfill * PR Feedback * Copy demo code over to auth-compat-layer, fix our build scripts (#3563) * Copy demo code over to auth-compat-layer, fix our build scripts * Add more functionality to compat layer * PR Feedback * PR Feedback * Fix more edge cases around auth-compat-exp polyfill (auth-next) (#3567) * Further refactoring of auth types. Add public exports to src/index.ts (#3078) * Further refactoring of auth types. Add public exports to src/index.ts * Add app-exp to devDependencies * PR feedback * Fix more edge cases around auth-compat-exp polyfill * Add uglified polyfill build for size comparison * PR feedback * Set ClientPlatform correctily in auth-exp and auth-compat-exp Co-authored-by: Sam Horlbeck Olsen <[email protected]> * Add platform specific persistence validation to auth-compat-exp (#3593) * Add an assertTypes utility (#3578) * Add assertTypes util * Add assertTypes function * Refactor project structure to support node (#3579) * Expose additionalUserInfo in auth-exp and auth-compat-exp (#3595) * Clean up our to/from JSON implementations (#3606) * Clean up our to/from JSON implementations - Remove anonymous credential/provider since they're not exposed and don't do anything - rename toPlainObject on User to toJSON per API spec - relax restrictions around ProviderId & SignInMethod typing since they can sometimes have values outside of our enum * PR feedback and more cleanup * Rejigger our error type checking to allow app-less errors * PR feedback * Register auth with the app component. Add the getAuth() methods for each platform (#3637) * Register auth with the app component. Add the getAuth() methods for each platform * Add getAuth for webworker build * Formatting * Make firebase auth implement _FirebaseService interface * Formatting * Fix tests * Formatting * PR feedback * Formatting * PR feedback * Formatting * Add the internal auth interface including proactive refresh (#3655) * Proactive refresh and internal SDK * Fix tests for node * Formatting * Remove unused file * PR feedback * Formatting * Implement cross-window browser events for auth-next (#3631) * Implement cross-window browser events for auth-next * Split out local & session storage * Add persistence events to indexed DB * Add some tests & fix a couple issues with local storage events * Add tests for AuthImpl._onStorageEvent and fix getIdToken to trigger correctly * Merge conflicts * PR feedback * Auth next build (#3654) * update package.json * make internal and main share code * remove unused deps and files * point to the right typing file for internal * cast internal Auth to public Auth to make TS happy * yarn.lock * Fix the broken build. (#3717) * Fix the broken build * Formatting * Fix compat build * Re-add demo * Fix build errors * Formatting * Fix linting for auth-compat-exp * Add hooks into auth-next for emulator config (#3716) * Add hooks into emulator for auth-next * Formatting * PR feedback * Fix broken tests * Formatting * Add assertions for type of OAuthProvider in popup/redirect (#3720) * Add assertion for the oauthprovider type in popup/redirect * Formatting * Remove circular dependency issue with AuthCredential (#3718) * Fix circular dependency issue * Formatting * Add origin validation to popup/redirect flows (#3730) * Add origin validation to the popup/redirect flows * Formatting * Cache the origin validation promise * Formatting * PR feedback * Formatting * Put some guardrails around the recaptcha host language param (#3734) * Add some guardrails for recaptcha host language param * Formatting * Prepare auth-next for merging to master (#3740) * suppress eslint error * fix type error * make auth-compat depend on app-compat * add release build for auth-exp * revert auth-compat to depend on app * test * don't abort on error for release builds * apply release build to web worker build * Revert "test" This reverts commit 8be511c. * fix lint error * Finish off the emulator hooks (#3732) * Finish emulator implementation * Formatting * Add appVerificationDisabledForTesting setting and the type to auth-types-exp * Formatting * Add network timeout cancellation to the core network code (#3771) * Add network timeout cancellation to core network code * Formatting * Fix broken test on CI * Formatting * Fix failing auth compat tests (#3783) * Fix the auth compat 'tests' * Formatting * Fix integration test * Formatting * Fix the phone integration test * Clear the redirect user on signout (#3784) * Clear redirect user upon signOut * Formatting * Fix issue in node * Formatting * Add user invalidation handling (#3804) * Add user invalidation handling * Formatting * Add a cache layer to the event manager (#3808) * Add caching of events to event manager * Formatting * Fix tests * Formatting * Handle null auth events from the iframe (#3818) * Add handling of null auth events * Formatting * Add web storage support check to popup actions (#3823) * Add web storage check to popup actions * Formatting * Update package.json * Fix gapi linter issue * Update auth-next deps before merging to master (#3809) * update dep version * update yarn lock * Ignore phone integration test in catch-all yarn:test Co-authored-by: Alex Volkovitsky <[email protected]> Co-authored-by: Feiyang1 <[email protected]> Co-authored-by: Scott Crossen <[email protected]> Co-authored-by: Feiyang <[email protected]>
1 parent 34c8693 commit a831aec

File tree

284 files changed

+50478
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

284 files changed

+50478
-3
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# @firebase/auth-compat-exp
2+
3+
This is a compatability layer to for the Firebase Authentication SDK
4+
5+
**This package is not intended for direct usage, and should only be used via the officially supported [firebase](https://www.npmjs.com/package/firebase) package.**

packages-exp/auth-compat-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+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
src/config.js
2+
.firebaserc
3+
public/config.js
4+
public/service-worker.*
5+
public/web-worker.*
6+
public/index.*
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Firebase-Auth for web - Auth Demo (Auth Compatibility Layer)
2+
3+
## Prerequisite
4+
5+
You need to have created a Firebase Project in the
6+
[Firebase Console](https://firebase.google.com/console/) as well as configured a web app.
7+
8+
## Installation
9+
Make sure you run `yarn` to install all dependencies in the root directory.
10+
11+
Enable the Auth providers you would like to offer your users in the console, under
12+
Auth > Sign-in methods.
13+
14+
Run:
15+
16+
```bash
17+
git clone https://github.com/firebase/firebase-js-sdk.git
18+
cd firebase-js-sdk/packages-exp/auth-compat-exp/demo
19+
```
20+
21+
This will clone the repository in the current directory.
22+
23+
If you want to be able to deploy the demo app to one of your own Firebase Hosting instance,
24+
configure it using the following command:
25+
26+
```bash
27+
firebase use --add
28+
```
29+
30+
Select the project you have created in the prerequisite, and type in `default` or
31+
any other name as the alias to use for this project.
32+
33+
Copy `public/sample-config.js` to `public/config.js`:
34+
35+
```bash
36+
cp public/sample-config.js public/config.js
37+
```
38+
39+
Then copy and paste the Web snippet config found in the console (either by clicking "Add Firebase to
40+
your web app" button in your Project overview, or clicking the "Web setup" button in the Auth page)
41+
in the `config.js` file.
42+
43+
In the `functions` folder you'll need to install the admin SDK:
44+
45+
```bash
46+
cd functions
47+
yarn install
48+
```
49+
50+
## Deploy
51+
52+
Before deploying, you may need to build the auth-exp package:
53+
```bash
54+
yarn build:deps
55+
```
56+
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.
64+
65+
To run the app locally, simply issue the following command in the `auth-compat-exp/demo` directory:
66+
67+
```bash
68+
yarn run demo
69+
```
70+
71+
This will compile all the files needed to run Firebase Auth, and start a Firebase server locally at
72+
[http://localhost:5000](http://localhost:5000).
73+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"rules": {
3+
".read": "auth != null",
4+
".write": "auth != null",
5+
"users": {
6+
"$user_id": {
7+
".read": "$user_id === auth.uid",
8+
".write": "$user_id === auth.uid"
9+
}
10+
}
11+
}
12+
}
13+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"database": {
3+
"rules": "database.rules.json"
4+
},
5+
"hosting": {
6+
"public": "public",
7+
"rewrites": [
8+
{
9+
"source": "/checkIfAuthenticated",
10+
"function": "checkIfAuthenticated"
11+
}
12+
]
13+
}
14+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* @license
3+
* Copyright 2018 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+
/**
19+
* @fileoverview Defines the HTTP endpoints hosted via firebase functions which
20+
* are used to test service worker functionality for Firebase Auth via demo
21+
* app.
22+
*/
23+
24+
const functions = require('firebase-functions');
25+
const admin = require('firebase-admin');
26+
27+
admin.initializeApp(functions.config().firebase);
28+
29+
exports.checkIfAuthenticated = functions.https.onRequest((req, res) => {
30+
const idToken = req.get('x-id-token');
31+
res.setHeader('Content-Type', 'application/json');
32+
if (idToken) {
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+
});
42+
} else {
43+
res.status(403).send(JSON.stringify({ error: 'Unauthorized access' }));
44+
}
45+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "functions",
3+
"description": "Cloud Functions for Firebase",
4+
"scripts": {
5+
"serve": "firebase serve --only functions",
6+
"shell": "firebase experimental:functions:shell",
7+
"start": "yarn shell",
8+
"deploy": "firebase deploy --only functions",
9+
"logs": "firebase functions:log"
10+
},
11+
"dependencies": {
12+
"firebase-admin": "8.11.0",
13+
"firebase-functions": "3.6.1"
14+
},
15+
"private": true
16+
}

0 commit comments

Comments
 (0)