aboutsummaryrefslogtreecommitdiff
path: root/pages/api/get-user.js
blob: 7df10a6061166699a1ce3c995a7977ed5cbea0a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import clientPromise from "../../lib/mongodb";

export async function getUser(userName) {
  const client = await clientPromise;
  const db = client.db("authbase");

  const collection = db.collection("users");
  const user = await collection.findOne({ name: userName });

  user._id = String(user._id);

  return user;
}

export default async function handler(req, res) {
  const { userName } = req.query;
  const user = await getUser(userName);

  res.status(200).json(user);
}