Create LoginRedirectMiddleware.md

This commit is contained in:
Christopher Saez 2017-03-08 23:03:39 +01:00 committed by GitHub
parent a302637061
commit 625130615f
1 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,22 @@
---
currentMenu: LoginRedirectMiddleware
---
# Login Redirect Middleware
`LoginRedirectMiddleware` is a Middleware to be used when you what to create an automatic redirection from any routes when the user is not authenticated.
## Examples
In your main.swift file
```swift
drop.grouped(LoginRedirectMiddleware(loginRoute: "/login")).group("admin") { routeAdmin in
let imagesViewController = ImagesViewController()
routeAdmin.get("images", handler: imagesViewController.indexView)
routeAdmin.get("images", Image.self, handler: imagesViewController.imageSelectedView)
}
```
> If the user is not connected when GET /admin/images is requested, user-agent will be redirected automatically to `/login` route