Skip to content

Commit

Permalink
Merge pull request #2 from zhuming15/user-authentication
Browse files Browse the repository at this point in the history
backend for forgot password
  • Loading branch information
zhuming15 authored Jun 30, 2023
2 parents 57d4841 + 4ce54c7 commit db2e697
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions project/my-project-name/backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ app.post('/api/delete-account', (req, res) => {
});
});

// Route for get email
app.post('/api/get-email', (req, res) => {
const email = req.body.email;
const query = `SELECT * FROM users WHERE email = ?`;

planetscale.query(query, email, (err, result) => {
if (!data || data.length === 0) {
return res.status(404).json({ error: 'Invalid Email' });
}
return res.status(200).json({ message: 'Accouont Exist' });
});
});

app.listen(PORT, () => {
console.log(`Server is running on ${PORT}`);
});
10 changes: 10 additions & 0 deletions project/my-project-name/frontend/src/components/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,18 @@ const deleteAccount = async (email, password) => {
}
};

const forgotPasswordDetails = async (email) => {
try {
const resp = await axios.get(`http://localhost:3002/api/delete-account`, { email: email });
return true;
} catch (err) {
return false;
}
};

export {
addNewUser,
checkLoginDetails,
deleteAccount,
forgotPasswordDetails,
};

0 comments on commit db2e697

Please sign in to comment.