Skip to content

Commit

Permalink
new
Browse files Browse the repository at this point in the history
  • Loading branch information
appujet committed Aug 30, 2023
1 parent 64a5948 commit 6aa2659
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
9 changes: 8 additions & 1 deletion src/api/middlewares/Middlewares.ts
Original file line number Diff line number Diff line change
@@ -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' });
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' });
}
};
2 changes: 1 addition & 1 deletion src/api/routes/auth/AuthRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 5 additions & 4 deletions src/api/services/guilds/GuildServices.ts
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -35,13 +36,13 @@ export async function getGuildChannels(guildId: string) {
}

export async function fetchRequest(url: string, auth): Promise<any> {
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();
}


2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 6aa2659

Please sign in to comment.