I followed this gist (https://gist.github.com/leabdalla/5999421) to achieve the goal, but because Sentry 2 uses different approach to implement in FuelPHP than Laravel it needed some additional code. So here is a solution for that.
Note that this is not perfect solution, and it could break when we do composer update, because it depends on current Sentry version.
You will need to create this file structure:
/app
/vendor
/Cartalyst
/Sentry
/Facades
/FuelPHP
SentryAdmin.php
FacadeAdmin.php
/Users
/Eloquent
Admin.php
######SentryAdmin.php
This file is same as FuelPHP Facade except we pass new model, session and cookie names to use with admin auth
######FacadeAdmin.php
Just extending Sentry Facade because we need new instance for handling Admin auth. Otherwise we won't be able to use both instances in same pass
######Admin.php
Admin user model. Extends Sentry User model. In this example I have changed login attribute, but thats just because I needed it. Its not required
After that we will need to load all that classes in botstrap.php file. Just add this:
Autoloader::add_classes(array(
// Separate Sentry instance used for admin auth
'Cartalyst\\Sentry\\Users\\Eloquent\\Admin' => APPPATH . 'vendor/Cartalyst/Sentry/Users/Eloquent/Admin.php',
'Cartalyst\\Sentry\\Facades\\FacadeAdmin' => APPPATH . 'vendor/Cartalyst/Sentry/Facades/FacadeAdmin.php',
'SentryAdmin' => APPPATH . 'vendor/Cartalyst/Sentry/Facades/FuelPHP/SentryAdmin.php',
));
You will need to copy users and users_groups database tables and rename them to admins and admins_groups
Also you will have to rename column user_id in admins_groups to admin_id
After that you are all set and you can use \SentryAdmin the same as you would use \Sentry. To test it do this in your code:
print_r(\Sentry::getUserProvider());
print_r(\SentryAdmin::getUserProvider());
and you should get objects with different models. Something like this:
// User object
Cartalyst\Sentry\Users\Eloquent\Provider
Object (
[model:protected] => Cartalyst\Sentry\Users\Eloquent\User
[hasher:protected] => Cartalyst\Sentry\Hashing\NativeHasher
)
// Admin object
Cartalyst\Sentry\Users\Eloquent\Provider
Object (
[model:protected] => Cartalyst\Sentry\Users\Eloquent\Admin
[hasher:protected] => Cartalyst\Sentry\Hashing\NativeHasher
)
I hope this helps someone. If you have any questions feel free to comment and I'll try to help.
Thanks to Leandro Abdalla for his solution that realy helped me a lot. His solution for Laravel can be found here: https://gist.github.com/leabdalla/5999421