From 4ce54c7a839fda8042e45d8e393ca5df837420d2 Mon Sep 17 00:00:00 2001 From: Shao Wei Date: Fri, 30 Jun 2023 17:03:22 +0800 Subject: [PATCH] backend for forgot password --- project/my-project-name/backend/index.js | 13 +++++++++++++ .../my-project-name/frontend/src/components/Api.js | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/project/my-project-name/backend/index.js b/project/my-project-name/backend/index.js index 553fd4d0..63986019 100644 --- a/project/my-project-name/backend/index.js +++ b/project/my-project-name/backend/index.js @@ -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}`); }); diff --git a/project/my-project-name/frontend/src/components/Api.js b/project/my-project-name/frontend/src/components/Api.js index 3620045e..2fc265fa 100644 --- a/project/my-project-name/frontend/src/components/Api.js +++ b/project/my-project-name/frontend/src/components/Api.js @@ -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, }; \ No newline at end of file