[Support Request]: Custom Controller In The Middleware Auth #2569

Closed
opened 2026-02-05 04:32:04 +03:00 by OVERLORD · 2 comments
Owner

Originally created by @rifkysyaripudin on GitHub (Jan 13, 2022).

Attempted Debugging

  • I have read the debugging page

Searched GitHub Issues

  • I have searched GitHub for the issue.

Describe the Scenario

Hi @ssddanbrown
Please help me. I want create custom controller in Theme, but in the group middleware auth. Every I create this, always redirect to home. But if I delete middleware it's normal like your video.

class CustomController extends Controller {
    public function index() {
        return response(['test'=>'Test '],200,['content-type'=>'text/plain']);
    }
}

Theme::listen(ThemeEvents::APP_BOOT, function() {
    Route::middleware('auth')->group(function() {
        Route::get('/test-controller', [CustomController::class, 'index']);
    });
});

Thanks

Exact BookStack Version

v21.12.1

Log Content

No response

PHP Version

8.0.1

Hosting Environment

Centos 7

Originally created by @rifkysyaripudin on GitHub (Jan 13, 2022). ### Attempted Debugging - [X] I have read the debugging page ### Searched GitHub Issues - [X] I have searched GitHub for the issue. ### Describe the Scenario Hi @ssddanbrown Please help me. I want create custom controller in Theme, but in the group middleware auth. Every I create this, always redirect to home. But if I delete middleware it's normal like your video. ```php class CustomController extends Controller { public function index() { return response(['test'=>'Test '],200,['content-type'=>'text/plain']); } } Theme::listen(ThemeEvents::APP_BOOT, function() { Route::middleware('auth')->group(function() { Route::get('/test-controller', [CustomController::class, 'index']); }); }); ``` Thanks ### Exact BookStack Version v21.12.1 ### Log Content _No response_ ### PHP Version 8.0.1 ### Hosting Environment Centos 7
OVERLORD added the 🐕 Support label 2026-02-05 04:32:04 +03:00
Author
Owner

@ssddanbrown commented on GitHub (Jan 13, 2022):

Hi @rifkysyaripudin,

I copied your example and this worked fine for me. By using the auth middleware you will need to be logged in to access the route, that's expected assuming your instance is not publicly accessible, otherwise you'll be redirected to login.

As another thing to check, what do your imports look like within your functions.php file? Do they look like this?:

use BookStack\Facades\Theme;
use BookStack\Http\Controllers\Controller;
use BookStack\Theming\ThemeEvents;
use Illuminate\Support\Facades\Route;
@ssddanbrown commented on GitHub (Jan 13, 2022): Hi @rifkysyaripudin, I copied your example and this worked fine for me. By using the `auth` middleware you will need to be logged in to access the route, that's expected assuming your instance is not publicly accessible, otherwise you'll be redirected to login. As another thing to check, what do your imports look like within your `functions.php` file? Do they look like this?: ```php use BookStack\Facades\Theme; use BookStack\Http\Controllers\Controller; use BookStack\Theming\ThemeEvents; use Illuminate\Support\Facades\Route; ```
Author
Owner

@ssddanbrown commented on GitHub (Jan 21, 2022):

Since there's been no follow-up I'm going to close this. Feel free to still comment if further support is needed and this can be re-opened.

@ssddanbrown commented on GitHub (Jan 21, 2022): Since there's been no follow-up I'm going to close this. Feel free to still comment if further support is needed and this can be re-opened.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#2569