Files
Open-Assistant/website/src/pages/api/messages/user.ts
T
2023-01-22 17:05:22 +07:00

25 lines
686 B
TypeScript

import { withoutRole } from "src/lib/auth";
import { getBackendUserCore } from "src/lib/users";
const handler = withoutRole("banned", async (req, res, token) => {
//TODO: add params if needed
const user = await getBackendUserCore(token.sub);
const params = new URLSearchParams({
username: user.id,
auth_method: user.auth_method,
});
const messagesRes = await fetch(`${process.env.FASTAPI_URL}/api/v1/messages?${params}`, {
method: "GET",
headers: {
"X-API-Key": process.env.FASTAPI_KEY,
},
});
const messages = await messagesRes.json();
// Send recieved messages to the client.
res.status(200).json(messages);
});
export default handler;