passport.js
1.19 KB
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
import dotenv from "dotenv";
import passport from "passport";
import GithubStrategy from "passport-github";
import FacebookStrategy from "passport-facebook";
import User from "./models/User";
import {
githubLoginCallback,
facebookLoginCallback,
} from "./controllers/userController";
import routes from "./routes";
dotenv.config();
// passport에게 strategy(로그인 방식)를 사용하도록 요청한다.
// passportLocalMongooser가 제공하는 strategy를 이용한다. -> username과 password를 사용.
passport.use(User.createStrategy());
passport.use(
new GithubStrategy(
{
clientID: process.env.GH_ID,
clientSecret: process.env.GH_SECRET,
callbackURL: `http://localhost:80${routes.githubCallback}`,
},
githubLoginCallback
)
);
passport.use(
new FacebookStrategy(
{
clientID: process.env.FB_ID,
clientSecret: process.env.FB_SECRET,
callbackURL: `https://77aa7153bcce.ngrok.io${routes.facebookCallback}`,
profileFields: ["id", "displayName", "photos", "email"],
scope: ["public_profile", "email"],
},
facebookLoginCallback
)
);
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());