Skip to content

Restricting Routes or controllers for auth status #257

Answered by jlopes90
slookabill asked this question in Q&A
Discussion options

You must be logged in to vote

The example is here.

App\Config\Routes.php

$routes->get('/admin/airports', 'Admin::airports', ['filter' => 'permission:admin.airports']);

App\Filters\PermissionFilter.php

<?php

namespace Shield\Filters;

use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Filters\FilterInterface;

use Shield\Exceptions\PermissionException;

class PermissionFilter implements FilterInterface
{
    public function before(RequestInterface $request, $params = null)
    {
        if (empty($params)) {
	    return;
        }
        
        if (!function_exists('auth')) {
	    helper('auth');
        }
        
        if (!auth()->loggedIn()) {
	    return redirect()->

Replies: 3 comments 13 replies

Comment options

You must be logged in to vote
3 replies
@slookabill
Comment options

@kenjis
Comment options

@MGatner
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
8 replies
@jlamping
Comment options

@kenjis
Comment options

@cdolister
Comment options

@foxbille
Comment options

@jlopes90
Comment options

Answer selected by kenjis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
8 participants