Implemented a simple authentication scheme with Firebase and Iron Session
This commit is contained in:
19
src/pages/api/exam/[module].ts
Normal file
19
src/pages/api/exam/[module].ts
Normal file
@@ -0,0 +1,19 @@
|
||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||
import type {NextApiRequest, NextApiResponse} from "next";
|
||||
import {app} from "@/firebase";
|
||||
import {getFirestore, collection, getDocs} from "firebase/firestore";
|
||||
|
||||
const db = getFirestore(app);
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const {module} = req.query as {module: string};
|
||||
|
||||
const snapshot = await getDocs(collection(db, module));
|
||||
|
||||
res.status(200).json(
|
||||
snapshot.docs.map((doc) => ({
|
||||
id: doc.id,
|
||||
...doc.data(),
|
||||
})),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user