blob: 9f652aca0f16eb7a6ef25df66df05eedb59cafb1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
// pages/api/update-user.js
import clientPromise from "../../lib/mongodb";
export default async function handler(req, res) {
const client = await clientPromise;
const db = client.db("authbase");
const collection = db.collection("users");
const { name, newData } = req.body; // id is the user ID and newData is the new data you want to set
try {
const result = await collection.updateOne(
{ name: name },
{ $set: newData }
);
res.status(200).json(result);
} catch (error) {
res.status(500).json({ error: "Unable to update user data" });
}
}
|