From ea2ebfb612582fcd71d791cd4f48b268b20326de Mon Sep 17 00:00:00 2001 From: "Jonny_Bro (Nikita)" Date: Fri, 6 Dec 2024 18:29:09 +0500 Subject: [PATCH] fix steam login --- index.js | 13 +++---------- routes/auth.js | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 routes/auth.js diff --git a/index.js b/index.js index 97e7150..682f66a 100644 --- a/index.js +++ b/index.js @@ -21,7 +21,8 @@ const indexRouter = require("./routes/index"), uploadRouter = require("./routes/upload"), adminRouter = require("./routes/admin"), apiRouter = require("./routes/api"), - statsRouter = require("./routes/stats"); + statsRouter = require("./routes/stats"), + authRouter = require("./routes/auth"); const app = express(); @@ -87,15 +88,7 @@ app.use("/upload", uploadRouter); app.use("/admin", adminRouter); app.use("/api", apiRouter); app.use("/stats", statsRouter); -app.get("/auth", passport.authenticate("steam"), () => {}); -app.get("/auth/return", passport.authenticate("steam", { failureRedirect: "/" }), (req, res) => res.redirect("/key")); -app.get("/auth/logout", (req, res, next) => { - req.logout(function (err) { - if (err) return next(err); - - res.redirect("/key"); - }); -}); +app.use("/auth", authRouter); /* catch 404 and forward to error handler app.use(function (req, res, next) { diff --git a/routes/auth.js b/routes/auth.js new file mode 100644 index 0000000..f8beb20 --- /dev/null +++ b/routes/auth.js @@ -0,0 +1,25 @@ +const express = require("express"), + router = express.Router(), + passport = require("passport"); + +router.get("/", passport.authenticate("steam"), () => {}); + +router.get( + "/return", + function (req, res, next) { + req.url = req.originalUrl; + next(); + }, + passport.authenticate("steam", { failureRedirect: "/" }), + (req, res) => res.redirect("/key"), +); + +router.get("/logout", (req, res, next) => { + req.logout(function (err) { + if (err) return next(err); + + res.redirect("/key"); + }); +}); + +module.exports = router;