Skip to content
Snippets Groups Projects
[userid].ts 627 B
Newer Older
Caner's avatar
Caner committed
import { NextApiRequest, NextApiResponse } from "next";

import { prisma } from "@/lib/db";

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
  if (req.method !== 'GET') {
    return res.status(405).end();
  }

  try {
    const { userId } = req.query;

    if (!userId || typeof userId !== 'string') {
      throw new Error('Invalid ID');
    }

    const existingUser = await prisma.user.findUnique({
      where: {
Yusuf Akgül's avatar
Yusuf Akgül committed
        id: +userId
Caner's avatar
Caner committed
      }
    });

Yusuf Akgül's avatar
Yusuf Akgül committed
    return res.status(200).json({ ...existingUser });
Caner's avatar
Caner committed
  } catch (error) {
    console.log(error);
    return res.status(400).end();
  }
};