From 463e0c5d23a66533f5c63c9cc505cbd7826b1a68 Mon Sep 17 00:00:00 2001 From: Joseph J Helfenbein Date: Sat, 25 Jan 2025 07:08:06 -0500 Subject: [PATCH] fix id --- src/app/api/user.js | 66 +++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/src/app/api/user.js b/src/app/api/user.js index 4096003..1c356c5 100644 --- a/src/app/api/user.js +++ b/src/app/api/user.js @@ -2,35 +2,37 @@ import User from '../../models/User'; import { connectDB } from '../../lib/utils'; export default async (req, res) => { - await connectDB(); - const { userId } = req.query; - - console.log('Received request with userId:', userId); - - if (!userId) { - console.log('No userId provided'); - return res.status(401).json({ message: 'Unauthorized' }); - } - - const user = await User.findOne({ clerkId: userId }); - - if (!user) { - console.log('User not found for clerkId:', userId); - return res.status(404).json({ message: 'User not found' }); - } - - if (req.method === 'GET') { - console.log('Returning user data:', user); - res.json(user); - } else if (req.method === 'PUT') { - const { role } = req.body; - console.log('Updating user role to:', role); - user.role = role; - await user.save(); - console.log('User role updated successfully'); - res.json(user); - } else { - console.log('Method not allowed:', req.method); - res.status(405).json({ message: 'Method not allowed' }); - } -}; \ No newline at end of file + const { userId } = req.query; + + console.log('Received request with userId:', userId); + + if (!userId) { + console.log('No userId provided'); + return res.status(401).json({ message: 'Unauthorized' }); + } + + await connectDB(); + + const user = await User.findOne({ id: userId }); + + if (!user) { + console.log('User not found for userId:', userId); + return res.status(404).json({ message: 'User not found' }); + } + + if (req.method === 'GET') { + console.log('Returning user data:', user); + res.json(user); + } else if (req.method === 'PUT') { + const { role } = req.body; + console.log('Updating user role to:', role); + user.role = role; + await user.save(); + console.log('User role updated successfully'); + res.json(user); + } else { + console.log('Method not allowed:', req.method); + res.status(405).json({ message: 'Method not allowed' }); + } + }; + \ No newline at end of file