Recent Topics

Admin user authentication in custom package



  • I have created a new package and it is linked from admin side menu. Now I want to implement admin user authentication to access the new package. How can I achieve this?



  • Hi,

    We are using ACL for the permisson & you can check it in admin package. (acl.php file in Config folder).
    Now you need to create same file in your package. (Path will be same as admin's acl file have).

    Now you need to merge your acl file with admin's acl file & you can do it in your service provider like this -

            $this->mergeConfigFrom(
                dirname(__DIR__) . '/Config/acl.php', 'acl'
            );
    

    Now you can create role (https://prnt.sc/of3qj6) and assign that role to specific user.

    Creation of acl file.

    You can create it like below -

    <?php

    return [
    [
    'key' => 'your package's key (generally name of package in small letter',
    'name' => 'name of package',
    'route' => 'route of your package ',
    'sort' => 'sorting order' (integer value for order of appearence)
    ]
    ];

    Thanks



  • Hi Rahul,
    Thans for your help. I had followed the steps you give. Now I am getting error as in the image shown

     ErrorException (E_ERROR)
    Trying to get property of non-object (View: D:\wamp64\www\bagisto\packages\MyTest\TestTest\src\Resources\views\testtest\create.blade.php)
    

    "Webkul\Admin\src\Providers\AdminServiceProvider.php", This file is highlighted, with these linkes
    $permissionType = auth()->guard('admin')->user()->role->permission_type;
    $allowedPermissions = auth()->guard('admin')->user()->role->permissions;

            protected function composeView()
        
            {
        
                view()->composer(['admin::layouts.nav-left', 'admin::layouts.nav-aside', 'admin::layouts.tabs'], function ($view) {
        
                    $tree = Tree::create();    
        
                    $permissionType = auth()->guard('admin')->user()->role->permission_type;    
                    $allowedPermissions = auth()->guard('admin')->user()->role->permissions;
        
    

    How to solve this issue?



  • Hi,

    Can you attach a screenshot of your acl file ?

    Thanks



  • Hi,
    This is my acl file

    <?php
    
    return [
    	[
    	'key' => 'mytest',
    	'name' => 'MyTest',
    	'route' => 'testtest.acl.create',
    	'sort' => '1'
    	]
    ];
    


  • Hi,

    Kindly confirm few things.

    1. Did you created custom role.
    2. Assigned that role to customer.

    If you followed all this steps & still getting this issue then kindly upload your package here, we will solved it.

    Thanks



  • Hi,
    I have updated the existing role and added my package to the role. The default role is assigned to the admin user.



  • Hi,

    Kindly upload zip of your package with database so that we can check.

    Thanks


Log in to reply