fix that shit
This commit is contained in:
parent
c2a23053c1
commit
b3d1a530b6
5 changed files with 20 additions and 12 deletions
|
@ -1,7 +1,6 @@
|
||||||
import { TrueSign } from "@/types/assist/extended_zodiac";
|
import { TrueSign } from "@/types/assist/extended_zodiac";
|
||||||
import { SubmitUser } from "@/types/client/user";
|
import { SubmitUser } from "@/types/client/user";
|
||||||
import { ClientUser, ServerUser } from "@/types/user";
|
import { ClientUser, ServerUser } from "@/types/user";
|
||||||
import { nanoid } from "nanoid";
|
|
||||||
import { getManyFlairs } from "../flair";
|
import { getManyFlairs } from "../flair";
|
||||||
import { cutArray, cutObject, removeCode, sanitize } from "../utility/merge";
|
import { cutArray, cutObject, removeCode, sanitize } from "../utility/merge";
|
||||||
import { ServerFlairToClientFlair } from "./flair";
|
import { ServerFlairToClientFlair } from "./flair";
|
||||||
|
@ -29,7 +28,7 @@ export function SubmitUserToServerUser(
|
||||||
let serverUser: Omit<Partial<ServerUser>, "_id"> = {
|
let serverUser: Omit<Partial<ServerUser>, "_id"> = {
|
||||||
...submitUser,
|
...submitUser,
|
||||||
flairs: [],
|
flairs: [],
|
||||||
code: submitUser.code || nanoid(16),
|
code: submitUser.code || "",
|
||||||
updatedDate: new Date()
|
updatedDate: new Date()
|
||||||
};
|
};
|
||||||
return serverUser;
|
return serverUser;
|
||||||
|
|
|
@ -37,9 +37,9 @@ export default async function handler(
|
||||||
} else if (method === "PUT") {
|
} else if (method === "PUT") {
|
||||||
let validatedTroll: Partial<SubmitTroll>;
|
let validatedTroll: Partial<SubmitTroll>;
|
||||||
try {
|
try {
|
||||||
validatedTroll = (await PartialUserSchema.validate(
|
validatedTroll = (await PartialUserSchema.validate(body, {
|
||||||
body
|
stripUnknown: true
|
||||||
)) as Partial<SubmitTroll>;
|
})) as Partial<SubmitTroll>;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return res.status(400).send(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 (checkUser == null) return res.status(404).end();
|
||||||
if (!compareCredentials(checkUser, cookies)) {
|
if (!compareCredentials(checkUser, cookies)) {
|
||||||
const thisUser = await getSingleUser({
|
const thisUser = await getSingleUser({
|
||||||
name: query.user
|
name: cookies.TROLLCALL_NAME
|
||||||
});
|
});
|
||||||
if (thisUser == null || !compareCredentials(thisUser, cookies))
|
if (thisUser == null || !compareCredentials(thisUser, cookies))
|
||||||
return res.status(403).end();
|
return res.status(403).end();
|
||||||
|
|
|
@ -14,7 +14,9 @@ export default async function handler(
|
||||||
if (method === "POST") {
|
if (method === "POST") {
|
||||||
let validatedTroll;
|
let validatedTroll;
|
||||||
try {
|
try {
|
||||||
validatedTroll = await SubmitTrollSchema.validate(body);
|
validatedTroll = await SubmitTrollSchema.validate(body, {
|
||||||
|
stripUnknown: true
|
||||||
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return res.status(400).send(err);
|
return res.status(400).send(err);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import {
|
||||||
import { changeUser, getSingleUser } from "@/lib/trollcall/user";
|
import { changeUser, getSingleUser } from "@/lib/trollcall/user";
|
||||||
import { PartialUserSchema, SubmitUser } from "@/types/client/user";
|
import { PartialUserSchema, SubmitUser } from "@/types/client/user";
|
||||||
import { serialize } from "cookie";
|
import { serialize } from "cookie";
|
||||||
|
import { nanoid } from "nanoid";
|
||||||
import { NextApiRequest, NextApiResponse } from "next";
|
import { NextApiRequest, NextApiResponse } from "next";
|
||||||
|
|
||||||
export default async function handler(
|
export default async function handler(
|
||||||
|
@ -28,9 +29,9 @@ export default async function handler(
|
||||||
} else if (method === "PUT") {
|
} else if (method === "PUT") {
|
||||||
let validatedUser: Partial<SubmitUser>;
|
let validatedUser: Partial<SubmitUser>;
|
||||||
try {
|
try {
|
||||||
validatedUser = (await PartialUserSchema.validate(
|
validatedUser = (await PartialUserSchema.validate(body, {
|
||||||
body
|
stripUnknown: true
|
||||||
)) as Partial<SubmitUser>;
|
})) as Partial<SubmitUser>;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return res.status(400).send(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 (checkExistingUser == null) return res.status(404).end();
|
||||||
if (!compareCredentials(checkExistingUser, cookies)) {
|
if (!compareCredentials(checkExistingUser, cookies)) {
|
||||||
const thisUser = await getSingleUser({
|
const thisUser = await getSingleUser({
|
||||||
name: query.user
|
name: cookies.TROLLCALL_NAME
|
||||||
});
|
});
|
||||||
if (thisUser == null || !compareCredentials(thisUser, cookies))
|
if (thisUser == null || !compareCredentials(thisUser, cookies))
|
||||||
return res.status(403).end();
|
return res.status(403).end();
|
||||||
|
@ -48,6 +49,8 @@ export default async function handler(
|
||||||
return res.status(403).end();
|
return res.status(403).end();
|
||||||
}
|
}
|
||||||
const serverUser = SubmitUserToServerUser(validatedUser);
|
const serverUser = SubmitUserToServerUser(validatedUser);
|
||||||
|
if (serverUser.code === "")
|
||||||
|
serverUser.code = checkExistingUser.code || nanoid(16);
|
||||||
const bothUsers = MergeServerUsers(checkExistingUser, serverUser);
|
const bothUsers = MergeServerUsers(checkExistingUser, serverUser);
|
||||||
const newUser = await changeUser(bothUsers);
|
const newUser = await changeUser(bothUsers);
|
||||||
if (newUser == null) return res.status(503).end();
|
if (newUser == null) return res.status(503).end();
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { createUser, getSingleUser } from "@/lib/trollcall/user";
|
||||||
import { SubmitUserSchema } from "@/types/client/user";
|
import { SubmitUserSchema } from "@/types/client/user";
|
||||||
import { ServerUser } from "@/types/user";
|
import { ServerUser } from "@/types/user";
|
||||||
import { serialize } from "cookie";
|
import { serialize } from "cookie";
|
||||||
|
import { nanoid } from "nanoid";
|
||||||
import { NextApiRequest, NextApiResponse } from "next";
|
import { NextApiRequest, NextApiResponse } from "next";
|
||||||
|
|
||||||
export default async function handler(
|
export default async function handler(
|
||||||
|
@ -13,7 +14,9 @@ export default async function handler(
|
||||||
if (method === "POST") {
|
if (method === "POST") {
|
||||||
let validatedUser;
|
let validatedUser;
|
||||||
try {
|
try {
|
||||||
validatedUser = await SubmitUserSchema.validate(body);
|
validatedUser = await SubmitUserSchema.validate(body, {
|
||||||
|
stripUnknown: true
|
||||||
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return res.status(400).send(err);
|
return res.status(400).send(err);
|
||||||
}
|
}
|
||||||
|
@ -26,6 +29,7 @@ export default async function handler(
|
||||||
ServerUser,
|
ServerUser,
|
||||||
"_id"
|
"_id"
|
||||||
>;
|
>;
|
||||||
|
if (serverUser.code === "") serverUser.code = nanoid(16);
|
||||||
const newUser = await createUser(serverUser);
|
const newUser = await createUser(serverUser);
|
||||||
if (newUser == null) return res.status(503).end();
|
if (newUser == null) return res.status(503).end();
|
||||||
// Give cookies
|
// Give cookies
|
||||||
|
|
Loading…
Reference in a new issue