-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassport.js
50 lines (47 loc) · 1.33 KB
/
passport.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
const passport = require("passport");
const { loginCredentials } = require("./config.js");
const { addOrUpdateInvestor } = require("./models/investor.js");
var GoogleStrategy = require("passport-google-oauth20").Strategy;
var GitHubStrategy = require("passport-github2").Strategy;
passport.use(
new GoogleStrategy(
{
clientID: loginCredentials.googleClientId,
clientSecret: loginCredentials.googleClientSecret,
callbackURL: "/auth/google/callback",
},
async function (accessToken, refreshToken, profile, done) {
const investorData = {
name: profile.displayName,
email: profile.emails[0].value,
investorId: profile.id,
};
const investor = await addOrUpdateInvestor(investorData);
return done(null, investor);
}
)
);
passport.use(
new GitHubStrategy(
{
clientID: loginCredentials.githubClientId,
clientSecret: loginCredentials.githubClientSecret,
callbackURL: "/auth/github/callback",
},
async function (accessToken, refreshToken, profile, done) {
const investorData = {
name: profile._json.name,
email: profile._json.email,
investorId: profile.id,
};
const investor = await addOrUpdateInvestor(investorData);
return done(null, investor);
}
)
);
passport.serializeUser((user, done) => {
done(null, user);
});
passport.deserializeUser((user, done) => {
done(null, user);
});