Created
September 5, 2023 14:46
-
-
Save rahulmore01/a0604ab7855aacac5d41e763ab55797e to your computer and use it in GitHub Desktop.
blog- get current loggedin user data api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import User from "@/models/userModel"; | |
| import { NextRequest, NextResponse } from "next/server"; | |
| import { connect } from "@/dbConfig/dbConfig"; | |
| import { getDataFromToken } from "@/helpers/jwt"; | |
| connect(); | |
| export async function GET(request: NextRequest) { | |
| try { | |
| const userId: any = await getDataFromToken(request); | |
| const user = await User.findOne({ | |
| _id: userId, | |
| }).select("-password"); | |
| return NextResponse.json({ message: "User found", data: user }); | |
| } catch (error: any) { | |
| return NextResponse.json({ error: error.message }, { status: 400 }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment