I got this code and if I call this api I will get the response as expected but nextjs is still complaining with the warning: API resolved without sending a response for /api/holders/xxx, this may result in stalled requests. How can i fix this problem?
const handler = async (req, res) => {
const { discordUserId, signedMessage, walletAddress } = req.body
if (req.method === "POST") {
// connect to db
sqlConnection.connect((err) => {
if (err) throw err
})
if (!(discordUserId && signedMessage && walletAddress))
return res.json({ message: "not verfified" })
// check if discord user id in database
sqlConnection.query(
`SELECT * FROM users WHERE discord_user_id = '${discordUserId}'`,
(err, result) => {
if (err) return res.json({ err })
// if discord user id not found add new discord user id and wallet address
if (result.length === 0) {
const userData = {
discord_user_id: discordUserId,
wallet_address: walletAddress
}
sqlConnection.query("INSERT INTO users SET ?", userData, (err) => {
if (err) return res.json({ err })
return res.json({ message: "added to database" })
})
} else {
// if discord user id found update wallet address
sqlConnection.query(
`UPDATE users SET wallet_address = '${walletAddress}' WHERE discord_user_id = '${discordUserId}'`,
(err) => {
if (err) return res.json({ err })
return res.json({ message: "wallet address updated" })
}
)
}
}
)
}
}