Skip to content

Commit

Permalink
Added middleware redirect instructions to guide
Browse files Browse the repository at this point in the history
  • Loading branch information
calebkleveter committed Nov 13, 2017
1 parent d309ae5 commit d4dbb07
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion docs/GitHub/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,17 @@ let token = try request.getAccessToken()
Now that you are authenticating the user, you will want to protect certain routes to make sure the user is authenticated. You can do this by adding the `ImperialMiddleware` to a droplet group:

```swift
let protected = drop.grouped(ImperialMiddleware)
let protected = drop.grouped(ImperialMiddleware())
```

Then, add your protected routes to the `protected` group:

```swift
protected.get("me", handler: me)
```

The `ImperialMiddleware` by default passes the errors it finds onto `ErrorMiddleware` where they are caught, but you can initialize it with a redirect path to go to if the user is not authenticated:

```swift
let protected = drop.grouped(ImperialMiddleware(redirect: "/"))
```

0 comments on commit d4dbb07

Please sign in to comment.