-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Closed
Description
I am trying to write a simple signup using Deno, and the following is my code:
async register(ctx: RouterContext) {
const { email, password } = await ctx.request.body().value;
let user = await User.findOne({ email });
if (user) {
ctx.response.status = 422;
ctx.response.body = { message: "Email is already exist" };
return;
}
const hashedPassword = hashSync(password);
user = new User({ email, password: hashedPassword });
await user.save();
ctx.response.status = 201;
ctx.response.body = {
id: user.id,
name: user.name,
email: user.email
};
}
The problem is that, what I get from the frontend side is like below:
{
email: "<email>",
password: "<password>"
}
But it seems my backend expects something like this:
{
value: {
email: "<email>",
password: "<password>"
}
}
And when I try to remove that .value part from the end of the following line of the code and change it like below:
const { email, password } = await ctx.request.body();
It gives me error messages like:
Property 'email' does not exist on type 'Body'.
Property 'password' does not exist on type 'Body'.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels