diff --git a/src/api/middlewares/Middlewares.ts b/src/api/middlewares/Middlewares.ts index 349e54404..596b41ffd 100644 --- a/src/api/middlewares/Middlewares.ts +++ b/src/api/middlewares/Middlewares.ts @@ -1,3 +1,10 @@ import { Request, Response, NextFunction } from 'express'; -export const IsAuth = (req: Request, res: Response, next: NextFunction) => req.user ? next() : res.sendStatus(401).send({ error: 'Unauthorized' }); \ No newline at end of file +export const IsAuth = (req: Request, res: Response, next: NextFunction) => { + console.log(`IsAuth: ${req.user}`); + if (req.user) { + next(); + } else { + res.status(401).json({ error: 'Unauthorized' }); + } +}; diff --git a/src/api/routes/auth/AuthRouter.ts b/src/api/routes/auth/AuthRouter.ts index b032be9d3..256ea13c6 100644 --- a/src/api/routes/auth/AuthRouter.ts +++ b/src/api/routes/auth/AuthRouter.ts @@ -13,7 +13,7 @@ class AuthRouter { res.sendStatus(200); }); this.router.get("/redirect", passport.authenticate("discord"), (req, res) => { - res.sendStatus(200); + res.redirect("/dashboard"); }); this.router.get("/me", this.getLogin); } diff --git a/src/api/services/guilds/GuildServices.ts b/src/api/services/guilds/GuildServices.ts index 45bfa52a5..8a31da223 100644 --- a/src/api/services/guilds/GuildServices.ts +++ b/src/api/services/guilds/GuildServices.ts @@ -1,7 +1,8 @@ -import { fetch } from "undici"; import { DISCORD_API_URL } from "../../types/types"; import config from "../../../config"; import { PrismaClient } from "@prisma/client"; +import { fetch } from "undici"; + const prisma = new PrismaClient(); export async function getBotGuildsService() { @@ -35,13 +36,13 @@ export async function getGuildChannels(guildId: string) { } export async function fetchRequest(url: string, auth): Promise { - let res = await fetch(url, { + const response = await fetch(url, { + method: "GET", headers: { Authorization: auth } }); - let data = await res.json(); - return data; + return await response.json(); } diff --git a/src/config.ts b/src/config.ts index bfd0a2e9d..de56015aa 100644 --- a/src/config.ts +++ b/src/config.ts @@ -14,7 +14,7 @@ export default { }, searchEngine: process.env.SEARCH_ENGINE || (SearchEngine.YouTube as SearchEngine), dashboard: { - port: parseInt(process.env.DASHBOARD_PORT) || 3000, + port: parseInt(process.env.DASHBOARD_PORT) || 3001, website: process.env.DASHBOARD_WEBSITE || 'http://localhost', enable: parseBoolean(process.env.DASHBOARD_ENABLE) || true, redirectUri: process.env.DASHBOARD_REDIRECT_URI || 'http://localhost:3000/api/auth/redirect',