I have a Koa 2 application, and this entry in / signup is processed by this function:
import User from 'models/user';
export const signup = async (ctx, next) => {
const { email, password } = ctx.request.body;
try {
const existingUser = await User.findOne({ email });
if (existingUser) {
ctx.body = { error: 'Email is in use' };
return next();
}
const user = new User({
email,
password,
});
await user.save();
ctx.body = { success: true };
} catch (e) {
next(e);
}
return next();
};
The funtion function receives the correct data, but await User.findOne().exec();never returns or gets stuck.
I think the problem is that if I delete, the code runs fine. If I switch to Promise, how ... find().thenIt works too. async / await works either, because if I go to expect fetch () (to emulate async), it works ... but here is my babel configuration
{
"presets" : ["latest", "stage-0"],
"plugins": [
["module-resolver", {
"root": ["./src"]
}]
]
}
mongoose - version 4.7.0
source
share