-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpassport-setup.js
39 lines (36 loc) · 995 Bytes
/
passport-setup.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
const passport = require('passport')
const GoogleStrategy = require("passport-google-oauth20").Strategy;
require("dotenv").config();
const db = require("./models");
const User = db.user
passport.serializeUser(function (user, done) {
done(null, user);
});
passport.deserializeUser(function (id, done) {
User.findOne({
where: {googleId: id.toString()}
}).then((user) => {
done(null, user)
})
});
passport.use(
new GoogleStrategy(
{
clientID: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET_KEY,
callbackURL: "https://stormboard-io.herokuapp.com/google/callback",
},
function (accessToken, refreshToken, profile, done) {
User.findOrCreate({
where: {
googleId: profile.id.toString(),
firstName: profile._json.given_name,
lastName: profile._json.family_name,
email: profile._json.email,
},
}).then((user) => {
return done(null, user);
});
}
)
);