Skip to content

Commit b8129b2

Browse files
committed
First pass at service workers for auth-next
1 parent e2efd27 commit b8129b2

24 files changed

+2172
-57
lines changed

packages-exp/auth-exp/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
module.exports = {
1919
extends: '../../config/.eslintrc.js',
20+
ignorePatterns: ['demo/'],
2021
parserOptions: {
2122
project: 'tsconfig.json',
2223
// to make vscode-eslint work with monorepo

packages-exp/auth-exp/demo/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
src/config.js
2-
.firebaserc
2+
.firebaserc
3+
public/service-worker.*
4+
public/web-worker.*
5+
public/index.*

packages-exp/auth-exp/demo/firebase.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
"rules": "database.rules.json"
44
},
55
"hosting": {
6-
"public": "public"
6+
"public": "public",
7+
"rewrites": [
8+
{
9+
"source": "/checkIfAuthenticated",
10+
"function": "checkIfAuthenticated"
11+
}
12+
]
713
}
814
}
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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
"engines": {
17+
"node": "10"
18+
}
19+
}

0 commit comments

Comments
 (0)