Blame view
client/routes/filters.coffee
882 Bytes
d1f4dbea8
|
1 |
### |
5f6f6fbb0
|
2 3 |
Route Filters Filters for managing user access to application routes. |
d1f4dbea8
|
4 5 6 |
### # Define Filters |
98c57048b
|
7 |
### |
5f6f6fbb0
|
8 9 10 |
Filter: Check if a User is Logged In If a user is not logged in and attempts to go to an authenticated route, re-route them to the login screen. |
98c57048b
|
11 |
### |
d1f4dbea8
|
12 |
checkUserLoggedIn = -> |
5f6f6fbb0
|
13 14 |
if not Meteor.loggingIn() and not Meteor.user() Router.go '/login' |
eeaf2c379
|
15 16 |
else @next() |
d1f4dbea8
|
17 |
|
98c57048b
|
18 |
### |
5f6f6fbb0
|
19 20 21 |
Filter: Check if a User Exists If a user is logged in and attempts to go to a public route, re-route them to the main "logged in" screen. |
98c57048b
|
22 |
### |
d1f4dbea8
|
23 |
userAuthenticated = -> |
5f6f6fbb0
|
24 25 |
if not Meteor.loggingIn() and Meteor.user() Router.go '/' |
eeaf2c379
|
26 27 |
else @next() |
d1f4dbea8
|
28 |
|
d1f4dbea8
|
29 |
# Run Filters |
d1f4dbea8
|
30 |
Router.onBeforeAction checkUserLoggedIn, except: [ |
5f6f6fbb0
|
31 32 33 34 |
'signup', 'login', 'recover-password', 'reset-password' |
d1f4dbea8
|
35 36 37 |
] Router.onBeforeAction userAuthenticated, only: [ |
5f6f6fbb0
|
38 39 40 41 |
'signup', 'login', 'recover-password', 'reset-password' |
d1f4dbea8
|
42 |
] |