Files
Open-Assistant/website/src/pages/api/messages/index.ts
T
jojopirker d0bc720761 inital try for navigation messages trees
should be redone probably in a recursive way...
2023-01-05 12:17:45 +01:00

25 lines
557 B
TypeScript

import { getToken } from "next-auth/jwt";
const handler = async (req, res) => {
const token = await getToken({ req });
// Return nothing if the user isn't registered.
if (!token) {
res.status(401).end();
return;
}
const messagesRes = await fetch(`${process.env.FASTAPI_URL}/api/v1/messages`, {
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;