-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.js
45 lines (41 loc) · 1.33 KB
/
helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const {OAuth2Client} = require('google-auth-library');
const client = new OAuth2Client("");
const models = require("./models/mongo/mongo");
module.exports = {
//CheckLoggedIN
checkLoggedIn: function (req, res, next) {
if (req.user)
next();
else {
// console.log("Unauthorized Access !");
res.redirect("/login");
}
},
getDocID: function (docname) {
models.doctor.findOne({
name: docname
})
.then((doc)=> {
return doc;
})
.catch((err) => {
console.log(err);
})
},
verify: async function(token) {
const ticket = await client.verifyIdToken({
idToken: token,
//audience: "575091130691-sio1vj6t19n6ofrao6bjggt694odf18v.apps.googleusercontent.com", // Specify the CLIENT_ID of the app that accesses the backend
// Or, if multiple clients access the backend:
//[CLIENT_ID_1, CLIENT_ID_2, CLIENT_ID_3]
});
const payload = ticket.getPayload();
const userid = payload['sub'];
console.log(userid,payload);
// If request specified a G Suite domain:
//const domain = payload['hd'];
},
afterAuth: function () {
console.log("User auth done. Next step");
}
};