In Vapor, I can easily secure routes in a login session with this:
drop.group(protect) {
secure in
secure.get("secureRoute", handler: )
secure.post("securePostRoute", handler: )
//and so forth
}
And the handler proceeds as usual, no checking for sessions, as it's already done by drop.group(protect)
.
However, in Kitura, it seems as though if I want to achieve the same thing, I'd have to do this:
router.get("/") {
request, response, next in
//Get the current session
sess = request.session
//Check if we have a session and it has a value for email
if let sess = sess, let email = sess["email"].string {
try response.send(fileName: pathToFile).end()
} else {
try response.send(fileName: pathToAnotherFile).end()
}
}
I'll have to manually check for the session in every secure route. This will end up being very redundant.
Is there any solution as elegant as Vapor's?