-
Notifications
You must be signed in to change notification settings - Fork 0
/
apiRoutes.js
73 lines (59 loc) · 1.46 KB
/
apiRoutes.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const express = require("express");
const passport = require("passport");
const Account = require("./account");
const router = express.Router();
router.get("/", (req, res) => {
res.render("index", { user: req.user });
});
router.get("/register", (req, res) => {
res.render("register", {});
});
router.post("/register", (req, res) => {
Account.register(new Account({ username: req.body.username }), req.body.password, (
err,
account
) => {
if (err) {
return res.render("register", { account });
}
passport.authenticate("local")(req, res, () => {
res.redirect("/");
});
});
});
router.get("/login", (req, res) => {
res.render("login", { user: req.user });
});
router.post("/login", passport.authenticate("local"), (req, res) => {
res.redirect("/");
});
router.get("/logout", (req, res) => {
req.logout();
res.redirect("/");
});
router.get("/ping", (req, res) => {
res.status(200).send("pong!");
});
// Setting the facebook oauth routes
const callbackSignin = function () {
console.log("Facebook auth callbackSignin");
};
const callbackSuccess = function () {
console.log("Facebook auth callbackSuccess");
};
router.get(
"/auth/facebook",
passport.authenticate("facebook", {
scope: ["email", "user_about_me"],
failureRedirect: "/",
}),
callbackSignin
);
router.get(
"/auth/facebook/callback",
passport.authenticate("facebook", {
failureRedirect: "/",
}),
callbackSuccess
);
module.exports = router;