mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 02:08:47 +00:00
Merge branch 'master' of https://github.com/ClaytonWWilson/CS307-Team24
This commit is contained in:
commit
a930353d79
3
.gitignore
vendored
3
.gitignore
vendored
@ -63,3 +63,6 @@ node_modules/
|
|||||||
|
|
||||||
# dotenv environment variables file
|
# dotenv environment variables file
|
||||||
.env
|
.env
|
||||||
|
|
||||||
|
# The keyfile for google services authentication
|
||||||
|
twistter-e4649-firebase-adminsdk-pgjve-1e57494429.json
|
||||||
@ -1,22 +1,78 @@
|
|||||||
|
/* eslint-disable promise/always-return */
|
||||||
const functions = require('firebase-functions');
|
const functions = require('firebase-functions');
|
||||||
const admin = require('firebase-admin');
|
const admin = require('firebase-admin');
|
||||||
|
const app = require('express')();
|
||||||
admin.initializeApp();
|
admin.initializeApp();
|
||||||
// // Create and Deploy Your First Cloud Functions
|
const db = admin.firestore();
|
||||||
// // https://firebase.google.com/docs/functions/write-firebase-functions
|
|
||||||
//
|
|
||||||
exports.helloWorld = functions.https.onRequest((request, response) => {
|
|
||||||
response.send("Hello from Firebase!");
|
|
||||||
});
|
|
||||||
|
|
||||||
exports.getUsername = functions.https.onRequest((req, res) => {
|
const firebaseConfig = {
|
||||||
admin.firestore().collection('users').get()
|
apiKey: "AIzaSyCvsWetg4qFdsPGfJ3LCw_QaaYzoan7Q34",
|
||||||
.then(data => {
|
authDomain: "twistter-e4649.firebaseapp.com",
|
||||||
|
databaseURL: "https://twistter-e4649.firebaseio.com",
|
||||||
|
projectId: "twistter-e4649",
|
||||||
|
storageBucket: "twistter-e4649.appspot.com",
|
||||||
|
messagingSenderId: "20131817365",
|
||||||
|
appId: "1:20131817365:web:633c95fb08b16d4526b89c"
|
||||||
|
};
|
||||||
|
|
||||||
|
const firebase = require('firebase');
|
||||||
|
firebase.initializeApp(firebaseConfig);
|
||||||
|
|
||||||
|
// Acts as a middleman between the client and any function that you use it with
|
||||||
|
// The function will only execute if the user is logged in, or rather, they have
|
||||||
|
// a valid token
|
||||||
|
const FBAuth = (req, resp, next) => {
|
||||||
|
let idToken;
|
||||||
|
|
||||||
|
if (req.headers.authorization && req.headers.authorization.startsWith('Bearer ')) {
|
||||||
|
idToken = req.headers.authorization.split('Bearer ')[1];
|
||||||
|
} else {
|
||||||
|
console.error('No token found');
|
||||||
|
return resp.status(403).json({ error: 'Unauthorized' });
|
||||||
|
}
|
||||||
|
|
||||||
|
admin.auth().verifyIdToken(idToken)
|
||||||
|
.then(decodedToken => {
|
||||||
|
req.user = decodedToken;
|
||||||
|
console.log(decodedToken);
|
||||||
|
return db.collection('users')
|
||||||
|
.where('userId', '==', req.user.uid)
|
||||||
|
.limit(1)
|
||||||
|
.get();
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
req.user.handle = data.docs[0].data().handle;
|
||||||
|
return next();
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error('Error verifying token', err);
|
||||||
|
return res.status(403).json(err);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
app.get('/getUsers', (req, res) => {
|
||||||
|
admin.firestore().collection('users').get().then(data => {
|
||||||
let users = [];
|
let users = [];
|
||||||
data.forEach(doc => {
|
data.forEach(doc => {
|
||||||
users.push(doc.data());
|
users.push(doc.data());
|
||||||
})
|
}); return res.json(users);
|
||||||
return res.json(users);
|
}).catch((err) => console.error(err));
|
||||||
})
|
});
|
||||||
.catch((err) => console.error(err));
|
|
||||||
})
|
app.post('/postUser', (req, res) => {
|
||||||
|
const newUser = {
|
||||||
|
body: req.body.body
|
||||||
|
};
|
||||||
|
admin.firestore().collection('users').add(newUser).then((doc) => {
|
||||||
|
res.json({
|
||||||
|
message: 'Successfully added!'
|
||||||
|
});
|
||||||
|
}).catch((err) => {
|
||||||
|
res.status(500).json({
|
||||||
|
error: "Error in posting user!"
|
||||||
|
});
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
exports.api = functions.https.onRequest(app);
|
||||||
1046
functions/package-lock.json
generated
1046
functions/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -13,6 +13,7 @@
|
|||||||
"node": "8"
|
"node": "8"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"firebase": "^6.6.1",
|
||||||
"firebase-admin": "^8.0.0",
|
"firebase-admin": "^8.0.0",
|
||||||
"firebase-functions": "^3.1.0"
|
"firebase-functions": "^3.1.0"
|
||||||
},
|
},
|
||||||
|
|||||||
12
twistter-e4649-firebase-adminsdk-pgjve-1e57494429.json
Normal file
12
twistter-e4649-firebase-adminsdk-pgjve-1e57494429.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"type": "service_account",
|
||||||
|
"project_id": "twistter-e4649",
|
||||||
|
"private_key_id": "1e57494429e4fd7d17f6fc28524e14b8e5227596",
|
||||||
|
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCyRdMZwXrpf3HB\nsVrGZVoPt+S+ahkT4SCCEWV/Q4O4hVyW277Rs0p7k5ZkZfkhcVVBUqKGMgW/Esvz\npx0VIgpg3gg308kMRmC3MGzYbodjynVyDHatyAZhhUi9cg0N2K9+vSsW5eSmWROe\nfVvB8hvr6m5xGVdJFA7DV4/0vm2cfy+Q/FlFb6vFmQTZtPZzGFf5BKoNMe7pMxey\n4zspAIZgRmxWDbAqqzX0PYk/WbXFgH/wn2X25S+ArHhoay2Hms65/NbWCV6mpFUJ\nYqzrlCn/WcwXGAm7tjmu00yD+bARabImh8R7+PSBaHMQ+SGdri2snIXWsvB/xi9/\nSNFqzHynAgMBAAECggEAVty/zapg1bnTt0FPziBfIA6FpaPzoSSN3uJUFozSdwuA\nAD+E/A9EiO7yFew71egvVrtJVmK0OxQRDSDNglkKPoWg8na+XL1D7a5qMpC0ZlKl\nJBNfljBCr6yuMySJqMf+Rp4siyUr4kO/0/cXyOnLYglhk7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E6eZ6CZWljFT\nHcuQ2cTFdB8bq8oLUxXeY3Yv\n-----END PRIVATE KEY-----\n",
|
||||||
|
"client_email": "firebase-adminsdk-pgjve@twistter-e4649.iam.gserviceaccount.com",
|
||||||
|
"client_id": "102241295911303209723",
|
||||||
|
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
||||||
|
"token_uri": "https://oauth2.googleapis.com/token",
|
||||||
|
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
||||||
|
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-pgjve%40twistter-e4649.iam.gserviceaccount.com"
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user