mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-23 07:41:02 +08:00
31 lines
692 B
TypeScript
31 lines
692 B
TypeScript
import sql from "~/server/components/postgres";
|
|
export default defineEventHandler(async (event) => {
|
|
if (event.method !== "POST") {
|
|
return {
|
|
error: "ERR_METHOD_NOT_ALLOWED",
|
|
};
|
|
}
|
|
const body = readBody(event);
|
|
if (!body.apiKey) {
|
|
return {
|
|
error: "ERR_API_KEY_REQUIRED",
|
|
};
|
|
}
|
|
const readUserToken = getCookie(event, "token");
|
|
if (!readUserToken) {
|
|
return {
|
|
error: "ERR_NOT_USER_LOGIN",
|
|
};
|
|
}
|
|
const verifyUserToken = await sql`
|
|
SELECT * FROM usertokens
|
|
where token=${readUserToken}
|
|
`;
|
|
if (verifyUserToken.length === 0) {
|
|
return {
|
|
error: "ERR_NOT_USER_LOGIN",
|
|
requested_action: "LOGOUT_USER",
|
|
};
|
|
}
|
|
});
|