2024-05-15 19:56:22 +00:00
|
|
|
import Express from "express";
|
|
|
|
|
import passport from "passport";
|
2024-05-16 11:56:46 +00:00
|
|
|
import { createLoginController } from "./controllers";
|
2024-05-23 15:38:41 +00:00
|
|
|
import { isUser } from "./passport";
|
2024-05-15 19:56:22 +00:00
|
|
|
|
|
|
|
|
export const AuthRouter = (appRouter: Express.Router) => {
|
|
|
|
|
const authRoutes: Express.Router = Express.Router({ mergeParams: true });
|
|
|
|
|
|
2024-05-23 15:38:41 +00:00
|
|
|
//appRouter.use(registerMiddleware("isUser", isUser));
|
|
|
|
|
//appRouter.use(registerMiddleware("isAdmin", isAdmin));
|
2024-05-15 19:56:22 +00:00
|
|
|
|
|
|
|
|
authRoutes.post(
|
|
|
|
|
"/login",
|
|
|
|
|
passport.authenticate("local-email", { session: false }),
|
|
|
|
|
(req: Express.Request, res: Express.Response, next: Express.NextFunction) =>
|
2024-05-23 15:38:41 +00:00
|
|
|
createLoginController(res.locals["context"]).execute(req, res, next)
|
2024-05-15 19:56:22 +00:00
|
|
|
);
|
|
|
|
|
|
2024-05-23 15:38:41 +00:00
|
|
|
authRoutes.post("/logout", isUser, (req: Express.Request, res: Express.Response) => {
|
|
|
|
|
//req.logout(); <-- ??
|
|
|
|
|
return res.status(200).json();
|
|
|
|
|
});
|
2024-05-16 18:16:00 +00:00
|
|
|
|
|
|
|
|
authRoutes.post("/register");
|
|
|
|
|
|
2024-05-15 19:56:22 +00:00
|
|
|
appRouter.use("/auth", authRoutes);
|
|
|
|
|
};
|