55 lines
1.8 KiB
JavaScript
55 lines
1.8 KiB
JavaScript
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||
|
});
|
||
|
};
|
||
|
import express from "express";
|
||
|
import passport from "passport";
|
||
|
const router = express.Router();
|
||
|
router.post("/signup", passport.authenticate("signup", { session: false }), (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
||
|
res.json({
|
||
|
message: "signup successful",
|
||
|
user: req.user
|
||
|
});
|
||
|
}));
|
||
|
router.post("/login", passport.authenticate('local'), function (req, res) {
|
||
|
console.log("BOOM!");
|
||
|
});
|
||
|
// router.post(
|
||
|
// '/login',
|
||
|
// async (req, res, next) => {
|
||
|
// passport.authenticate(
|
||
|
// 'login',
|
||
|
// async (err, user, info) => {
|
||
|
// try {
|
||
|
// if (err || !user) {
|
||
|
// const error = new Error('An error occurred.');
|
||
|
//
|
||
|
// return next(error);
|
||
|
// }
|
||
|
//
|
||
|
// req.login(
|
||
|
// user,
|
||
|
// { session: false },
|
||
|
// async (error) => {
|
||
|
// if (error) return next(error);
|
||
|
//
|
||
|
// const body = { _id: user._id, email: user.email };
|
||
|
// const token = jwt.sign({ user: body }, 'TOP_SECRET');
|
||
|
//
|
||
|
// return res.json({ token });
|
||
|
// }
|
||
|
// );
|
||
|
// } catch (error) {
|
||
|
// return next(error);
|
||
|
// }
|
||
|
// }
|
||
|
// )(req, res, next);
|
||
|
// }
|
||
|
// );
|
||
|
export default router;
|