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