koa-passport-example icon indicating copy to clipboard operation
koa-passport-example copied to clipboard

[question] function based authentication route

Open sibelius opened this issue 8 years ago • 3 comments

// Require authentication for now
app.use(function(ctx, next) {
  if (ctx.isAuthenticated()) {
    return next()
  } else {
    ctx.redirect('/')
  }
})

is there a way to require authentication per route ? like this:

app.use(isAuthenticated(), async ctx => { ctx.body = 'this is restricted'; })

sibelius avatar Feb 14 '16 00:02 sibelius