Blame view
client/routes/hooks.js
958 Bytes
3b214be5e
|
1 |
/* |
03f51985e
|
2 3 |
* Route Hooks * Hook functions for managing user access to routes. |
3b214be5e
|
4 5 6 |
*/ /* |
03f51985e
|
7 |
* Define Hook Functions |
3b214be5e
|
8 9 10 |
*/ /* |
03f51985e
|
11 |
* Hook: Check if a User is Logged In |
3b214be5e
|
12 13 14 15 16 17 18 19 20 21 22 23 24 |
* If a user is not logged in and attempts to go to an authenticated route, * re-route them to the login screen. */ checkUserLoggedIn = function(){ if( !Meteor.loggingIn() && !Meteor.user() ) { Router.go('/login'); } else { this.next(); } } /* |
03f51985e
|
25 |
* Hook: Check if a User Exists |
3b214be5e
|
26 |
* If a user is logged in and attempts to go to a public route, re-route |
03f51985e
|
27 |
* them to the index path. |
3b214be5e
|
28 29 30 31 32 33 34 35 36 37 38 |
*/ userAuthenticated = function(){ if( !Meteor.loggingIn() && Meteor.user() ){ Router.go('/'); } else { this.next(); } } /* |
03f51985e
|
39 |
* Run Hooks |
3b214be5e
|
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
*/ Router.onBeforeAction(checkUserLoggedIn, { except: [ 'signup', 'login', 'recover-password', 'reset-password' ] }); Router.onBeforeAction(userAuthenticated, { only: [ 'signup', 'login', 'recover-password', 'reset-password' ] }); |