Commit 72dec6a20930891bf87ba509904305fd853e3689

Authored by Ryan Glover
Exists in master

Merge branch 'refactor/filters_to_hooks_#25'

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