Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IronRouter authorisation controller

I'm wondering if anyone could demonstrate how to use a global 'before' action on a router controller class that handles user authentication and displays the appropriate route/template based on the result.

My use case is to have an AppController that acts as an authentication firewall and blocks any child controller actions when a user is logged out. E.g.

// Create a primary app controller stub with the auth firewall
AppController = RouteController.extend({});

// Extend the AppController with all the other app routes
MainController = AppController.extend({});

Any help would be appreciated!

like image 672
Chris Waring Avatar asked Aug 26 '13 20:08

Chris Waring


1 Answers

In my blog written in meteor I use code :

AppController = RouteController.extend({
  before:function(){
    if(_.isNull(Meteor.user())){
      Router.go(Router.path('home'));
    }
  }
})

AdminPostController = AppController.extend({
  waitOn: function() { return App.subs.posts}
});

Router.map(function(){
  this.route('submitPost', {
    path: '/submitPost',
    controller:'AdminPostController',
    template:'postCreate'
  });
  this.route('editPost', {
    path: '/post/:slug/edit',
    controller:'AdminPostController',
    template:'postEdit'
  });
})
like image 177
Kuba Wyrobek Avatar answered Sep 30 '22 12:09

Kuba Wyrobek