-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from FahimFBA/116-bug-add-2fa-two-factor-auth…
…entication-features-like-authy 116 bug add 2fa two factor authentication features like authy
- Loading branch information
Showing
18 changed files
with
7,446 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"projects": { | ||
"default": "assistme-f18bb" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"functions": [ | ||
{ | ||
"source": "functions", | ||
"codebase": "default", | ||
"ignore": [ | ||
"node_modules", | ||
".git", | ||
"firebase-debug.log", | ||
"firebase-debug.*.log" | ||
], | ||
"predeploy": [ | ||
"npm --prefix \"$RESOURCE_DIR\" run lint" | ||
] | ||
} | ||
], | ||
"firestore": { | ||
"rules": "firestore.rules", | ||
"indexes": "firestore.indexes.json" | ||
}, | ||
"emulators": { | ||
"functions": { | ||
"port": 5001 | ||
}, | ||
"firestore": { | ||
"port": 8080 | ||
}, | ||
"database": { | ||
"port": 9000 | ||
}, | ||
"pubsub": { | ||
"port": 8085 | ||
}, | ||
"storage": { | ||
"port": 9199 | ||
}, | ||
"ui": { | ||
"enabled": true | ||
}, | ||
"singleProjectMode": true, | ||
"auth": { | ||
"port": 9099 | ||
} | ||
}, | ||
"storage": { | ||
"rules": "storage.rules" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"indexes": [], | ||
"fieldOverrides": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
rules_version = '2'; | ||
|
||
service cloud.firestore { | ||
match /databases/{database}/documents { | ||
match /{document=**} { | ||
allow read, write: if true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module.exports = { | ||
env: { | ||
es6: true, | ||
node: true, | ||
}, | ||
parserOptions: { | ||
"ecmaVersion": 2018, | ||
}, | ||
extends: [ | ||
"eslint:recommended", | ||
"google", | ||
], | ||
rules: { | ||
"no-restricted-globals": ["error", "name", "length"], | ||
"prefer-arrow-callback": "error", | ||
"quotes": ["error", "double", {"allowTemplateLiterals": true}], | ||
}, | ||
overrides: [ | ||
{ | ||
files: ["**/*.spec.*"], | ||
env: { | ||
mocha: true, | ||
}, | ||
rules: {}, | ||
}, | ||
], | ||
globals: {}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* Import function triggers from their respective submodules: | ||
* | ||
* const {onCall} = require("firebase-functions/v2/https"); | ||
* const {onDocumentWritten} = require("firebase-functions/v2/firestore"); | ||
* | ||
* See a full list of supported triggers at https://firebase.google.com/docs/functions | ||
*/ | ||
|
||
import { onRequest } from "firebase-functions/v2/https"; | ||
import * as logger from "firebase-functions/logger"; | ||
import admin from "firebase-admin"; | ||
admin.initializeApp(); | ||
import speakeasy from "speakeasy"; | ||
import { onDocumentWritten } from "firebase-functions/v2/firestore"; | ||
|
||
export const helloWorld = onRequest((request, response) => { | ||
logger.info("Hello logs!", { structuredData: true }); | ||
response.send("Hello from Firebase!"); | ||
}); | ||
|
||
export const registerUser = onRequest((request, response) => { | ||
var secret = speakeasy.generateSecret({ length: 20 }); | ||
logger.info("Hello logs!", { structuredData: true }); | ||
response.json({ msg: "Hello from Fireb", secret }); | ||
}); | ||
|
||
export const verifyUser = onRequest((request, response) => { | ||
const { secret, token } = request.body; | ||
const verified = speakeasy.totp.verify({ | ||
secret: secret.base32, | ||
encoding: "base32", | ||
token, | ||
}); | ||
response.json({ verified }); | ||
}); | ||
|
||
export const updateDocumentCounts = onDocumentWritten( | ||
"documents/{documentsId}", | ||
async () => { | ||
const db = admin.firestore(); | ||
const documentCountRef = db.collection("documentCount").doc("count"); | ||
|
||
// Get the total count of documents in the "documents" collection | ||
const documentsCollectionRef = db.collection("documents"); | ||
const documentsQuerySnapshot = await documentsCollectionRef.get(); | ||
const totalCount = documentsQuerySnapshot.size; | ||
|
||
// Update the "count" field in the "documentCount" collection | ||
await documentCountRef.set({ count: totalCount }); | ||
|
||
logger.info(totalCount, { | ||
structuredData: true, | ||
}); | ||
}, | ||
); | ||
|
||
export const addAuthSecret = onDocumentWritten( | ||
"users/{usersId}", | ||
async (snapshot) => { | ||
const db = admin.firestore(); | ||
const singleUserRef = db | ||
.collection("authSecrets") | ||
.doc(snapshot?.params?.usersId); | ||
const getAllUserData = await singleUserRef.get(); | ||
|
||
// Generate a secret | ||
const secret = speakeasy.generateSecret({ length: 20 }); | ||
|
||
// console.log( | ||
// "Updating user document with secret:", | ||
// snapshot?.params?.usersId, | ||
// getAllUserData.data(), | ||
// ); | ||
|
||
if (getAllUserData.data()?.secret) { | ||
return; | ||
} else { | ||
await singleUserRef.set({ secret }); | ||
} | ||
|
||
logger.info("User Created/ Updated", { | ||
structuredData: true, | ||
}); | ||
}, | ||
); |
Oops, something went wrong.