ŞİFRE YENİLEME
```javascript
export async function changePassword(prev, formData) {
const password = formData.get("password");
const confirmPassword = formData.get("confirmPassword");
const currentPassword = formData.get("currentPassword");
if (!password || !confirmPassword || !currentPassword) {
return { message: "All fields are required!" };
}
if (password !== confirmPassword) {
return { message: "Passwords do not match!" };
}
try {
const session = await auth();
if (!session || !session.user || !session.user.email) {
return { message: "User not found!" };
}
const foundUser = await prisma.user.findUnique({
where: {
id: session.user.id,
},
});
if (!foundUser) {
return { message: "User not found!" };
}
const isMatch = bcrypt.compareSync(currentPassword, foundUser.password);
if (!isMatch) {
return { message: "Current password is incorrect!" };
}
const salt = bcrypt.genSaltSync(10);
const hash = bcrypt.hashSync(password, salt);
await prisma.user.update({
where: {
id: session.user.id,
},
data: {
password: hash,
},
});
return { message: "Password updated successfully!" };
} catch (error) {
console.error(error);
return { message: "Something went wrong!" };
}
}
```javascriptreact
import PasswordForm from "../components/PasswordForm";
```
Last updated