Answer the question
In order to leave comments, you need to log in
How to redirect in Koa.js?
Why is the redirect not happening, what am I doing wrong? Thanks in advance
router.post('/login', async ctx => {
const username = ctx.request.body.fields.username;
const password = ctx.request.body.fields.password;
if (username.length < 3 || password.length < 6) {
console.error("User enter not correct login data");
ctx.res.writeHead(300, "Username or password lenght is to small");
return;
}
if (!users.find(obj => obj.username === username)) {
users.push(ctx.request.body.fields);
console.log("New user...");
} else {
console.log("Old user...");
}
ctx.redirect('/');
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question