Skip to content

Commit 6d95707

Browse files
author
Okanlawon Jamiu
committed
Implemented Cloud Functions
1 parent 4312fd5 commit 6d95707

10 files changed

Lines changed: 2821 additions & 0 deletions

File tree

functions/.firebaserc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"projects": {
3+
"default": "appandup-2be33"
4+
}
5+
}

functions/.gitignore

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
firebase-debug.log*
8+
firebase-debug.*.log*
9+
10+
# Firebase cache
11+
.firebase/
12+
13+
# Firebase config
14+
15+
# Uncomment this if you'd like others to create their own Firebase project.
16+
# For a team working on the same Firebase project(s), it is recommended to leave
17+
# it commented so all members can deploy to the same project(s) in .firebaserc.
18+
# .firebaserc
19+
20+
# Runtime data
21+
pids
22+
*.pid
23+
*.seed
24+
*.pid.lock
25+
26+
# Directory for instrumented libs generated by jscoverage/JSCover
27+
lib-cov
28+
29+
# Coverage directory used by tools like istanbul
30+
coverage
31+
32+
# nyc test coverage
33+
.nyc_output
34+
35+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
36+
.grunt
37+
38+
# Bower dependency directory (https://bower.io/)
39+
bower_components
40+
41+
# node-waf configuration
42+
.lock-wscript
43+
44+
# Compiled binary addons (http://nodejs.org/api/addons.html)
45+
build/Release
46+
47+
# Dependency directories
48+
node_modules/
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Optional REPL history
57+
.node_repl_history
58+
59+
# Output of 'npm pack'
60+
*.tgz
61+
62+
# Yarn Integrity file
63+
.yarn-integrity
64+
65+
# dotenv environment variables file
66+
.env

functions/firebase.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"firestore": {
3+
"rules": "firestore.rules",
4+
"indexes": "firestore.indexes.json"
5+
},
6+
"functions": {
7+
"predeploy": [
8+
"npm --prefix \"$RESOURCE_DIR\" run lint"
9+
],
10+
"source": "functions"
11+
},
12+
"emulators": {
13+
"auth": {
14+
"port": 9099
15+
},
16+
"functions": {
17+
"port": 5001
18+
},
19+
"firestore": {
20+
"port": 8080
21+
},
22+
"ui": {
23+
"enabled": true
24+
}
25+
}
26+
}

functions/firestore.indexes.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"indexes": [],
3+
"fieldOverrides": []
4+
}

functions/firestore.rules

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
rules_version = '2';
2+
service cloud.firestore {
3+
match /databases/{database}/documents {
4+
match /{document=**} {
5+
allow read, write: if
6+
request.time < timestamp.date(2021, 11, 13);
7+
}
8+
}
9+
}

functions/functions/.eslintrc.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
es6: true,
5+
node: true,
6+
},
7+
extends: [
8+
"eslint:recommended",
9+
"google",
10+
],
11+
rules: {
12+
quotes: ["error", "double"],
13+
},
14+
};

functions/functions/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

functions/functions/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const functions = require("firebase-functions");
2+
const admin = require("firebase-admin");
3+
admin.initializeApp();
4+
5+
const auth = admin.auth();
6+
const firestore = admin.firestore();
7+
8+
exports.deleteUserAccount = functions.https.onCall(async (data, context) => {
9+
try {
10+
await firestore.collection("users").doc(context.auth.uid).delete();
11+
12+
await auth.deleteUser(context.auth.uid);
13+
14+
return 'User was successfully deleted';
15+
} catch (error) {
16+
throw 'Error deleting User';
17+
}
18+
});

0 commit comments

Comments
 (0)