forked from burakorkmez/mern-advanced-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added change password function
- Loading branch information
Showing
9 changed files
with
373 additions
and
76 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,5 @@ export const mailtrapClient = new MailtrapClient({ | |
|
||
export const sender = { | ||
email: "[email protected]", | ||
name: "Burak", | ||
name: "MT5 Webhook", | ||
}; |
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { useState } from "react"; | ||
import { motion } from "framer-motion"; | ||
import { useAuthStore } from "../store/authStore"; | ||
import Input from "../components/Input"; | ||
import { Lock } from "lucide-react"; | ||
import toast from "react-hot-toast"; | ||
|
||
const ChangePasswordPage = () => { | ||
const [currentPassword, setCurrentPassword] = useState(""); | ||
const [newPassword, setNewPassword] = useState(""); | ||
const [confirmNewPassword, setConfirmNewPassword] = useState(""); | ||
const { changePassword, error, isLoading } = useAuthStore(); | ||
|
||
const handleSubmit = async (e) => { | ||
e.preventDefault(); | ||
|
||
if (newPassword !== confirmNewPassword) { | ||
alert("New passwords do not match"); | ||
return; | ||
} | ||
try { | ||
await changePassword(currentPassword, newPassword); | ||
toast.success("Password changed successfully"); | ||
} catch (error) { | ||
console.error(error); | ||
toast.error(error.message || "Error changing password"); | ||
} | ||
}; | ||
|
||
return ( | ||
<motion.div | ||
initial={{ opacity: 0, y: 20 }} | ||
animate={{ opacity: 1, y: 0 }} | ||
transition={{ duration: 0.5 }} | ||
className='max-w-md w-full bg-gray-800 bg-opacity-50 backdrop-filter backdrop-blur-xl rounded-2xl shadow-xl overflow-hidden' | ||
> | ||
<div className='p-8'> | ||
<h2 className='text-3xl font-bold mb-6 text-center bg-gradient-to-r from-green-400 to-emerald-500 text-transparent bg-clip-text'> | ||
Change Password | ||
</h2> | ||
{error && <p className='text-red-500 text-sm mb-4'>{error}</p>} | ||
|
||
<form onSubmit={handleSubmit}> | ||
<Input | ||
icon={Lock} | ||
type='password' | ||
placeholder='Current Password' | ||
value={currentPassword} | ||
onChange={(e) => setCurrentPassword(e.target.value)} | ||
required | ||
/> | ||
<Input | ||
icon={Lock} | ||
type='password' | ||
placeholder='New Password' | ||
value={newPassword} | ||
onChange={(e) => setNewPassword(e.target.value)} | ||
required | ||
/> | ||
<Input | ||
icon={Lock} | ||
type='password' | ||
placeholder='Confirm New Password' | ||
value={confirmNewPassword} | ||
onChange={(e) => setConfirmNewPassword(e.target.value)} | ||
required | ||
/> | ||
<motion.button | ||
whileHover={{ scale: 1.02 }} | ||
whileTap={{ scale: 0.98 }} | ||
className='w-full py-3 px-4 bg-gradient-to-r from-green-500 to-emerald-600 text-white font-bold rounded-lg shadow-lg hover:from-green-600 hover:to-emerald-700 focus:outline-none focus:ring-2 focus:ring-green-500 focus:ring-offset-2 focus:ring-offset-gray-900 transition duration-200' | ||
type='submit' | ||
disabled={isLoading} | ||
> | ||
{isLoading ? "Changing..." : "Change Password"} | ||
</motion.button> | ||
</form> | ||
</div> | ||
</motion.div> | ||
); | ||
}; | ||
|
||
export default ChangePasswordPage; |
This file contains 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
Oops, something went wrong.