From 03f51985e003012c3adaa84b233886f3106b4e36 Mon Sep 17 00:00:00 2001 From: Ryan Glover Date: Fri, 16 Jan 2015 22:13:37 -0600 Subject: [PATCH] Rename client/routes/filters.js to hooks.js. Swap filter label for hook in /client/routes/hooks.js. --- client/routes/filters.js | 58 ------------------------------------------------ client/routes/hooks.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 58 deletions(-) delete mode 100644 client/routes/filters.js create mode 100644 client/routes/hooks.js diff --git a/client/routes/filters.js b/client/routes/filters.js deleted file mode 100644 index 67fd089..0000000 --- a/client/routes/filters.js +++ /dev/null @@ -1,58 +0,0 @@ -/* -* Route Filters -* Filters for managing user access to application routes. -*/ - -/* -* Define Filters -*/ - -/* -* 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. -*/ - -checkUserLoggedIn = function(){ - if( !Meteor.loggingIn() && !Meteor.user() ) { - Router.go('/login'); - } else { - this.next(); - } -} - -/* -* 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. -*/ - -userAuthenticated = function(){ - if( !Meteor.loggingIn() && Meteor.user() ){ - Router.go('/'); - } else { - this.next(); - } -} - -/* -* Run Filters -*/ - -Router.onBeforeAction(checkUserLoggedIn, { - except: [ - 'signup', - 'login', - 'recover-password', - 'reset-password' - ] -}); - -Router.onBeforeAction(userAuthenticated, { - only: [ - 'signup', - 'login', - 'recover-password', - 'reset-password' - ] -}); diff --git a/client/routes/hooks.js b/client/routes/hooks.js new file mode 100644 index 0000000..3037615 --- /dev/null +++ b/client/routes/hooks.js @@ -0,0 +1,58 @@ +/* +* Route Hooks +* Hook functions for managing user access to routes. +*/ + +/* +* Define Hook Functions +*/ + +/* +* Hook: 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. +*/ + +checkUserLoggedIn = function(){ + if( !Meteor.loggingIn() && !Meteor.user() ) { + Router.go('/login'); + } else { + this.next(); + } +} + +/* +* Hook: Check if a User Exists +* If a user is logged in and attempts to go to a public route, re-route +* them to the index path. +*/ + +userAuthenticated = function(){ + if( !Meteor.loggingIn() && Meteor.user() ){ + Router.go('/'); + } else { + this.next(); + } +} + +/* +* Run Hooks +*/ + +Router.onBeforeAction(checkUserLoggedIn, { + except: [ + 'signup', + 'login', + 'recover-password', + 'reset-password' + ] +}); + +Router.onBeforeAction(userAuthenticated, { + only: [ + 'signup', + 'login', + 'recover-password', + 'reset-password' + ] +}); -- 2.0.0