Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/forget api #48

Open
wants to merge 6 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 130 additions & 2 deletions wonderlust/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion wonderlust/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
"dependencies": {
"axios": "^1.7.9",
"bcryptjs": "^2.4.3",
"jsonwebtoken": "^9.0.2",
"mongoose": "^8.9.5",
"next": "15.1.5",
"passport": "^0.7.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-icons": "^5.4.0"
"react-icons": "^5.4.0",
"react-toastify": "^11.0.3"
},
"devDependencies": {
"@types/node": "22.10.10",
Expand Down
35 changes: 35 additions & 0 deletions wonderlust/src/app/api/auth/reset_password/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { HttpStatusCode } from 'axios';
import connectMongo from '../../../../../util/connect-mongo';
import User from '../../../../../models/User';
import { CreateUserDto } from '../../../../../dto/create-user.dto';
import { NextRequest, NextResponse } from 'next/server';
import bcryptjs from "bcryptjs";

export async function PUT(req: NextRequest) {
try {
await connectMongo();
const body: CreateUserDto = await req.json();
const {email, password} = body
if (email && password) {
const salt = await bcryptjs.genSalt(10)
const hashedPassword = await bcryptjs.hash(password, salt)

const userCheck = await User.findOne({ email });

if(!userCheck){
return NextResponse.json({error: "User not found"}, {status: 404})
}

userCheck.password = hashedPassword;
await userCheck.save();

return NextResponse.json(
{ status: HttpStatusCode.Ok, message:"Password updated successfully" },
);
}
return NextResponse.json({ message: 'Missing field' }, { status: HttpStatusCode.BadRequest });
} catch (error) {
return NextResponse.json({ message: error }, { status: HttpStatusCode.BadRequest });
}
}