el.xwx.moe/pages/api/hello.ts

32 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-04-23 08:26:39 -05:00
// Copyright (C) 2022-present Daniel31x13 <daniel31x13@gmail.com>
// This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
2023-01-31 05:36:56 -06:00
import type { NextApiRequest, NextApiResponse } from "next";
2023-02-06 11:59:23 -06:00
import { getServerSession } from "next-auth/next";
import { authOptions } from "pages/api/auth/[...nextauth]";
2023-01-29 12:12:36 -06:00
type Data = {
2023-02-06 11:59:23 -06:00
message: string;
data?: object;
2023-01-31 05:36:56 -06:00
};
2023-01-29 12:12:36 -06:00
2023-01-31 05:36:56 -06:00
export default async function handler(
2023-01-29 12:12:36 -06:00
req: NextApiRequest,
res: NextApiResponse<Data>
) {
2023-02-06 11:59:23 -06:00
const session = await getServerSession(req, res, authOptions);
console.log(session);
if (!session) {
res.status(401).json({ message: "You must be logged in." });
return;
}
return res.json({
message: "Success",
});
2023-01-29 12:12:36 -06:00
}