2023-04-18 09:23:55 +02:00
|
|
|
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
|
|
|
import {databasePromise} from "../../../libs/cloud/mongodb";
|
|
|
|
import {getServerSession} from "next-auth"
|
|
|
|
import {authOptions} from "../auth/[...nextauth]";
|
|
|
|
|
2023-04-21 06:59:37 +02:00
|
|
|
export const handler = async (req, res) => {
|
2023-04-18 09:23:55 +02:00
|
|
|
const session = await getServerSession(req, res, authOptions)
|
|
|
|
let db = await databasePromise;
|
|
|
|
|
|
|
|
const { method, body } = req;
|
|
|
|
|
|
|
|
switch (method) {
|
|
|
|
case 'GET':
|
|
|
|
let cloudConfig = await db.collection('cloud_configs').findOne({ userId: session.userId });
|
|
|
|
res.send(JSON.stringify(cloudConfig, null, 2))
|
|
|
|
break;
|
|
|
|
case 'POST': // set
|
|
|
|
await db.collection('cloud_configs').updateOne(
|
|
|
|
{ userId: session.userId },
|
|
|
|
{
|
|
|
|
$set: body,
|
|
|
|
},
|
|
|
|
{ upsert: true },
|
|
|
|
);
|
|
|
|
res.send(JSON.stringify(session, null, 2))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-04-21 06:59:37 +02:00
|
|
|
};
|
|
|
|
export default handler;
|