Shield - redirect after login |
hi,
i need to protect route 'bookmark/init' and have noticed that after login, user is redirected to '/'. To have him redirected to what he requested : "bookmark/init' my solution is the following, and my question is : is this dumb, and is there a better way ? My code : in app\Config\Routes.php PHP Code: $routes->get('bookmark/init','Bookmark::init',['filter' => 'perm:users.edit']); in app\Config\Filter.php PHP Code: public array $aliases = [ in App\Filters\PermissionFilter.php PHP Code: public function before(RequestInterface $request, $params = null) First : I use alias perm in Routes, because, when you use Permission PHP Code: $routes->get('bookmark/init','Bookmark::init',['filter' => 'permission:users.edit']); PHP Code: public array $aliases = [
It is not good. Because the code "service('settings')->set('Auth.redirects', ['login' => $path])" updates the Config value in the database.
That is, the config values is global, and it is shared by all requests. If a user gets bookmark/init, it sets Auth.redirects to ['login' => 'bookmark/init']. And after that, all users will be redirected to bookmark/init after logged in. If you have more than one protected page, this may happen: 1. user A sets Auth.redirects to ['login' => 'bookmark/init'] 2. user B sets Auth.redirects to ['login' => 'another'] 3. user A is logged in, and redirected to 'another' 4. user B is logged in, and redirected to 'another' (04-12-2023, 06:01 AM)kenjis Wrote: It is not good. Because the code "service('settings')->set('Auth.redirects', ['login' => $path])" updates the Config value in the database. I understand, and agree, but what is the good way ?
Shield User Guide - Custom Redirect URLs
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(08-06-2023, 11:19 PM)InsiteFX Wrote: Shield User Guide - Custom Redirect URLs Thanks for help Have modified my solution (exposed above) : Url requested by user, before filling the Shield login form, is saved in session in some App\Filters\permissionFilter And is retrieved (and destroyed) in Shield RedirectAfterLogin() of Auth.php function Can show code here for those who need Eric
Yes, please show the code to help other users learn how to do it.
Thank you. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
When only some routes of app are protected, you might have to find a solution to redirect user after login
In my App, I managed things like this : First create a filter named permissionFilter.php in directory App\Filters PHP Code: <?php PHP Code: <?php PHP Code: /** PHP Code: $routes->match(['get','post'],'personne/update/(:num)','Personne::update/$1', ['filter' => 'perm:users.edit']);
@foxbille I don't know exactly what the issue is.
Are you looking for a topic similar to the below? https://github.com/codeigniter4/shield/discussions/722 If yes, it is implemented in branch develop and can be used. (09-05-2023, 12:02 PM)datamweb Wrote: @foxbille I don't know exactly what the issue is.Thank ! That works pretty well. Was it implemented in a very recent version of Shield ??? |
Welcome Guest, Not a member yet? Register Sign In |