cleaning
This commit is contained in:
parent
e05a0856e2
commit
284171c7e9
@ -3,7 +3,6 @@ import { getConnection } from "@/db";
|
||||
import { Post, postPlaceholder } from "@/model/Models";
|
||||
import { getPosts, IPost } from "@/controller/Post";
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
// import { MPost, MUser, MAuth } from "@/model/Models"
|
||||
import { MPost } from "@/model/sequelize/Post";
|
||||
import { MUser } from "@/model/sequelize/User";
|
||||
import { MAuth } from "@/model/sequelize/Auth";
|
||||
@ -27,7 +26,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
return;
|
||||
}
|
||||
};
|
||||
const auth = getAuth() || ["",""];
|
||||
const auth = getAuth() || ["", ""];
|
||||
console.log(auth);
|
||||
const username = auth[0];
|
||||
const password = auth[1];
|
||||
@ -37,20 +36,20 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
|
||||
let user = await MUser.findOne({ where: { username: username } });
|
||||
if (user == undefined) {
|
||||
res.status(401).json("User does not exist");
|
||||
return;
|
||||
res.status(401).json("User does not exist");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(await validatePassword(password, user.password))) {
|
||||
res.status(401).json("Invalid password");
|
||||
return;
|
||||
res.status(401).json("Invalid password");
|
||||
return;
|
||||
}
|
||||
|
||||
let authtoken = await MAuth.findOne({ where: { user_id: user.id } });
|
||||
if (authtoken == undefined) {
|
||||
if (user.id != undefined) {
|
||||
authtoken = await MAuth.create({ user_id: user.id });
|
||||
}
|
||||
if (user.id != undefined) {
|
||||
authtoken = await MAuth.create({ user_id: user.id });
|
||||
}
|
||||
}
|
||||
|
||||
res.status(200).json(authtoken);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user