fix that shit

This commit is contained in:
MeowcaTheoRange 2023-07-01 02:22:12 -05:00
parent c2a23053c1
commit b3d1a530b6
5 changed files with 20 additions and 12 deletions

View file

@ -1,7 +1,6 @@
import { TrueSign } from "@/types/assist/extended_zodiac";
import { SubmitUser } from "@/types/client/user";
import { ClientUser, ServerUser } from "@/types/user";
import { nanoid } from "nanoid";
import { getManyFlairs } from "../flair";
import { cutArray, cutObject, removeCode, sanitize } from "../utility/merge";
import { ServerFlairToClientFlair } from "./flair";
@ -29,7 +28,7 @@ export function SubmitUserToServerUser(
let serverUser: Omit<Partial<ServerUser>, "_id"> = {
...submitUser,
flairs: [],
code: submitUser.code || nanoid(16),
code: submitUser.code || "",
updatedDate: new Date()
};
return serverUser;

View file

@ -37,9 +37,9 @@ export default async function handler(
} else if (method === "PUT") {
let validatedTroll: Partial<SubmitTroll>;
try {
validatedTroll = (await PartialUserSchema.validate(
body
)) as Partial<SubmitTroll>;
validatedTroll = (await PartialUserSchema.validate(body, {
stripUnknown: true
})) as Partial<SubmitTroll>;
} catch (err) {
return res.status(400).send(err);
}
@ -49,7 +49,7 @@ export default async function handler(
if (checkUser == null) return res.status(404).end();
if (!compareCredentials(checkUser, cookies)) {
const thisUser = await getSingleUser({
name: query.user
name: cookies.TROLLCALL_NAME
});
if (thisUser == null || !compareCredentials(thisUser, cookies))
return res.status(403).end();

View file

@ -14,7 +14,9 @@ export default async function handler(
if (method === "POST") {
let validatedTroll;
try {
validatedTroll = await SubmitTrollSchema.validate(body);
validatedTroll = await SubmitTrollSchema.validate(body, {
stripUnknown: true
});
} catch (err) {
return res.status(400).send(err);
}

View file

@ -11,6 +11,7 @@ import {
import { changeUser, getSingleUser } from "@/lib/trollcall/user";
import { PartialUserSchema, SubmitUser } from "@/types/client/user";
import { serialize } from "cookie";
import { nanoid } from "nanoid";
import { NextApiRequest, NextApiResponse } from "next";
export default async function handler(
@ -28,9 +29,9 @@ export default async function handler(
} else if (method === "PUT") {
let validatedUser: Partial<SubmitUser>;
try {
validatedUser = (await PartialUserSchema.validate(
body
)) as Partial<SubmitUser>;
validatedUser = (await PartialUserSchema.validate(body, {
stripUnknown: true
})) as Partial<SubmitUser>;
} catch (err) {
return res.status(400).send(err);
}
@ -40,7 +41,7 @@ export default async function handler(
if (checkExistingUser == null) return res.status(404).end();
if (!compareCredentials(checkExistingUser, cookies)) {
const thisUser = await getSingleUser({
name: query.user
name: cookies.TROLLCALL_NAME
});
if (thisUser == null || !compareCredentials(thisUser, cookies))
return res.status(403).end();
@ -48,6 +49,8 @@ export default async function handler(
return res.status(403).end();
}
const serverUser = SubmitUserToServerUser(validatedUser);
if (serverUser.code === "")
serverUser.code = checkExistingUser.code || nanoid(16);
const bothUsers = MergeServerUsers(checkExistingUser, serverUser);
const newUser = await changeUser(bothUsers);
if (newUser == null) return res.status(503).end();

View file

@ -3,6 +3,7 @@ import { createUser, getSingleUser } from "@/lib/trollcall/user";
import { SubmitUserSchema } from "@/types/client/user";
import { ServerUser } from "@/types/user";
import { serialize } from "cookie";
import { nanoid } from "nanoid";
import { NextApiRequest, NextApiResponse } from "next";
export default async function handler(
@ -13,7 +14,9 @@ export default async function handler(
if (method === "POST") {
let validatedUser;
try {
validatedUser = await SubmitUserSchema.validate(body);
validatedUser = await SubmitUserSchema.validate(body, {
stripUnknown: true
});
} catch (err) {
return res.status(400).send(err);
}
@ -26,6 +29,7 @@ export default async function handler(
ServerUser,
"_id"
>;
if (serverUser.code === "") serverUser.code = nanoid(16);
const newUser = await createUser(serverUser);
if (newUser == null) return res.status(503).end();
// Give cookies