Answer the question
In order to leave comments, you need to log in
How can I access a variable in an async method?
await sendEmail(req.body.email, this.verificationCode) throws an error that this.verificationCode = undefined, how can I fix this?
class VerificationCodeController{
constructor(){
this.verificationCode = generateCode()
}
async sendCode(req, res){
await sendEmail(req.body.email, this.verificationCode)
return res.json(responseCreator.response(this.verificationCode));
}
}
Answer the question
In order to leave comments, you need to log in
Are you initializing variables in the constructor? If so, check what the generateCode() function returns
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question