MCPcopy Create free account
hub / github.com/Bitbox-Connect/Bitbox / ResetPasswordByEmail

Function ResetPasswordByEmail

server/Controllers/auth.js:103–144  ·  view source on GitHub ↗
(req, res)

Source from the content-addressed store, hash-verified

101};
102
103async function ResetPasswordByEmail(req, res) {
104
105 const VITE_CLIENT_PORT = process.env.VITE_CLIENT_PORT || "https://bitbox-in.netlify.app";
106 const { email } = req.body;
107
108 // Check if email is provided
109 if (!email) {
110 return res.status(400).json({ error: 'Email is required' });
111 }
112
113 const user = await User.findOne({ email });
114
115 if (!user) {
116 return res.status(404).json({ error: 'User does not exist' });
117 }
118
119 const transporter = nodemailer.createTransport({
120 service: "gmail",
121 auth: {
122 user: process.env.EMAIL_USER,
123 pass: process.env.EMAIL_PASS,
124 },
125 });
126
127 const mailOptions = {
128 from: process.env.EMAIL_USER,
129 to: email,
130 subject: "Reset Your Password on BitBox",
131 html: `
132 <p>Reset your password using the link below:</p>
133 <a href="${VITE_CLIENT_PORT}/reset-password"><button>Click here</button></a> to reset your password
134 `,
135 };
136
137 transporter.sendMail(mailOptions, (error, info) => {
138 if (error) {
139 return res.status(500).json({ error: "Error sending email" });
140 } else {
141 return res.status(200).json({ message: "Email sent successfully" });
142 }
143 });
144}
145
146
147const forgetpassword = async (req, res) => {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected