forked from iamakashrout/Team_Curious
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (47 loc) · 1.39 KB
/
index.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
46
47
48
49
50
51
52
53
54
55
const express = require('express');
const app = express();
const passport = require('passport');
const cookieSession = require('cookie-session');
require('./passport');
app.use(cookieSession({
name: 'google-auth-session',
keys: ['key1', 'key2']
}));
app.use(express.static('public'));
app.use(passport.initialize());
app.use(passport.session());
app.set('view engine', 'ejs');
app.get('/', (req, res) => {
// res.send("<button><a href='/auth'>Login With Google</a></button>")
res.render("main")
});
// Auth
app.get('/auth/google' , passport.authenticate('google', { scope:
[ 'email', 'profile' ]
}));
app.get("/patient_log",function(req,res){
res.render("patient_login");
});
app.get("/doctor_log",function(req,res){
res.render("doctor_login");
})
// Auth Callback
app.get( '/auth/callback',
passport.authenticate( 'google', {
successRedirect: '/auth/callback/success',
failureRedirect: '/auth/callback/failure'
}));
// Success
app.get('/auth/callback/success' , (req , res) => {
if(!req.user)
res.redirect('/auth/callback/failure');
//res.send("Welcome " + req.user.email);
res.render("patientprofile");
});
// failure
app.get('/auth/callback/failure' , (req , res) => {
res.send("Error");
})
app.listen(4000 , () => {
console.log("Server Running on port 4000");
});