Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Shield getPermissions returns an empty array
#1

(This post was last modified: 04-22-2023, 08:22 AM by grimpirate.)

I'm using the following spark command to create three default users for testing purposes:
PHP Code:
<?php

namespace App\Commands;

use 
CodeIgniter\CLI\BaseCommand;
use 
CodeIgniter\CLI\CLI;

use 
CodeIgniter\Shield\Entities\User;

class 
SettingsCommand extends BaseCommand
{
    protected $group 'Setup';

    protected $name 'setup:initial';

    protected $description 'Initializes assorted defaults';

    protected $usage 'setup:initial';

    public function run(array $params)
    {

    helper('setting');

 
setting('Auth.allowRegistration'false);

 
$this->registerUser([
 
'username' => 'admin',
 
'email' => '[email protected]',
 
'password' => 'omgapassword',
 ], 
'superadmin');

 
$this->registerUser([
 
'name_first' => 'JANE',
 
'name_last' => 'DOE',
 
'title_job' => 'Big Boss',
 
'username' => 'boss',
 
'email' => '[email protected]',
 
'password' => 'omgapassword',
 ], 
'admin');

 
$this->registerUser([
 
'name_first' => 'Jane',
 
'name_last' => 'Doe',
 
'title_job' => 'Little Cog',
 
'username' => 'user',
 
'email' => '[email protected]',
 
'password' => 'omgapassword',
 ], 
'user');
    }

    private function registerUser($data$group)
    {
    $users auth()->getProvider();
 
$user = new User($data);
 
$users->save($user);
 
$user $users->findById($users->getInsertID());
 
$user->syncGroups($group);
    }

After successful login, I land on my homepage which issues:
PHP Code:
print_r(auth()->user()->getPermissions()); 
However, the output is an empty array. Shouldn't this be an array with all the default permissions for shield for the particular group type of the user (I realize that the user group is empty, I'm getting the same result for admin and superadmin)? I'm also using a custom UserModel class that provides the extra fields: name_first, name_last, title_job

Same issue as described in this post.
Reply


Messages In This Thread
[SOLVED] Shield getPermissions returns an empty array - by grimpirate - 04-21-2023, 08:23 AM



Theme © iAndrew 2016 - Forum software by © MyBB