W
W
Wasya UK2018-02-20 23:53:01
JavaScript
Wasya UK, 2018-02-20 23:53:01

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

1 answer(s)
M
Mikhail, 2018-02-21
@mak_ufo

Perhaps because of return

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question