Created
October 31, 2022 22:05
-
-
Save Josh4324/62908da7ffd90cc2e1e59a291d26a269 to your computer and use it in GitHub Desktop.
login.js
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
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction | |
export default function handler(req, res) { | |
if (req.method === "POST") { | |
// Parse incoming request body and get the email | |
const email = JSON.parse(req.body).email; | |
// option object, filter checks for email in the database | |
const options = { | |
method: "POST", | |
headers: { | |
Authorization: process.env.XATA, | |
"Content-Type": "application/json", | |
}, | |
body: `{"filter":{"email":{"$contains":"${email}"}},"page":{"size":15}}`, | |
}; | |
(async () => { | |
try { | |
// get user data, if email exist in the database. | |
const response = await fetch( | |
`${process.env.database}:main/tables/users/query`, | |
options | |
); | |
const data = await response.json(); | |
return res.status(200).json(data.records); | |
} catch (err) { | |
return res.status(500).json({ message: "An error occured" }); | |
} | |
})(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment