From 065bb11f4f4794c4382938ca668426dbf7e7a6bd Mon Sep 17 00:00:00 2001 From: oxdev03 <140103378+oxdev03@users.noreply.github.com> Date: Sat, 23 Mar 2024 13:23:07 +0100 Subject: [PATCH] fix id search --- apps/dashboard/middleware/auth.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/dashboard/middleware/auth.ts b/apps/dashboard/middleware/auth.ts index a1c0cbe..5a60239 100644 --- a/apps/dashboard/middleware/auth.ts +++ b/apps/dashboard/middleware/auth.ts @@ -1,4 +1,3 @@ -import { ObjectId } from "mongodb"; import { Document } from "mongoose"; import { NextApiRequest, NextApiResponse } from "next"; import { getToken } from "next-auth/jwt"; @@ -14,7 +13,7 @@ const authHandler = await connectDB(); const token = await getToken({ req }); if (!token) return res.status(401).end(); - const user = await UserModel.findOne({ _id: new ObjectId(token.sub) }); + const user = await UserModel.findById(token.sub); if (!user) return res.status(401).end(); return handler(req, res, user); };