Added user authentication.

This commit is contained in:
Daniel
2023-02-06 21:29:23 +03:30
parent 882bbd64d1
commit e5ed2ec5db
16 changed files with 657 additions and 83 deletions
+16 -3
View File
@@ -1,13 +1,26 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { getServerSession } from "next-auth/next";
import { authOptions } from "pages/api/auth/[...nextauth]";
type Data = {
name: string;
message: string;
data?: object;
};
export default async function handler(
req: NextApiRequest,
res: NextApiResponse<Data>
) {
console.log("Triggered hello.ts");
res.status(200).json({ name: "John Doe" });
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",
});
}