The Post Auth Hook

A new feature was added to Community Auth on January 7th, 2016. This new feature, a post auth hook, is an empty method that is called after an authentication method is called in one of your controllers.

As a usage example, consider the following scenario; your website has a menu, and the menu has a login/logout link, and that link is created in consideration of the user’s login status. Using the post auth hook, you could use the authentication variables to build the menu for all of your pages, and then use the Loader’s var method to set the menu globally.

Override the Method

The first thing to do would be to add a post_auth_hook method to your MY_Controller:

// Add this method to My_Controller.php
protected function post_auth_hook()
{
   // code ...
}

Add Your Own Functionality

Since we were talking about a menu that considers the auth status, we would use authentication variables in a view to dynamically create it. All you would need to do to make it available globally would be something like this:

protected function post_auth_hook()
{
   $this->load->vars( 
      array( 'main_menu' => $this->load->view('menus/main', '', TRUE ) ) 
   );
}