barryvdh / laravel-elfinder

elFinder bundle for Laravel
739 stars 171 forks source link

Laravel elfinder custom auth #220

Closed vietnguyen09 closed 6 years ago

vietnguyen09 commented 6 years ago

My project is Laravel 5.4, I use Laravel-elfinder by Barryvdh, it works very nice but when I append my authenticate middleware, is not work as my expected.

Expected: Only authenticated user can use Elfinder Right now: Login success but elfinder cannot recognize session, Auth::user() is null

I'm using custom auth class and here is my AuthVerification.php middleware.

<?php

namespace App\Http\Middleware;

use App\Libraries\Routes\Routes;
use Closure;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;

class AuthVerification
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if(!Auth::check()){
            return redirect('/guest/login');
        }
        return $next($request);
    }
}

I put this middleware info config/elfinder.php but when I access and login http://example.com/elfinder/tinymce4 my Auth::user() always null when I dd(Auth::user()) in ElfinderController.php and tinymce4.blade.php

'route' => [
    'prefix' => 'elfinder',
    'middleware' => 'AuthVerification', //Set to null to disable middleware filter
],

Does need any specific way to make my custom auth class work with elfinder?

vietnguyen09 commented 6 years ago

Found solution, sorry

'route' => [
    'prefix' => 'elfinder',
    'middleware' => ['web','AuthVerification'], //Set to null to disable middleware filter
],